2016-04-20 6 views
0

を提出していません。フォームは依然として提出しません(または、データベースに接続するために作成した "voted.php"にリダイレクトします)。ラジオボタンは適切にクリックされていますが、リダイレクトだけではありません。必要なものを記入した後、私のフォームは

これは私のコードです:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Vote</title> 
</head> 

<body> 

<h1>Please note that you only get to vote one time. Look carefully and make a wise choice.</h1> 

<form method="post" action="vote_process.php" > 

<div class="section"> 
<strong>Matriculation Number:</strong> 
    <input type="text" size="30" maxlength="16" name="Reg_Num" /><br /> 
</div> 
<p><p></p></p> 



<div class="section"> 
    <form> 
    <h3><strong>President:</strong></h3> 
    <input type="radio" name="radio_array[]" value="Presi_1" name="President_1" />President 1 
    <input type="radio" name="radio_array[]" value="Presi 2" name="President_2" />President 2 
    </form> 
</div> 

<p></p><p></p> 
<div class="section"> 
    <form> 
    <h3><strong>Vice President:</strong></h3> 
    <input type="radio" name="radio_array[]" value="VP1" name="Vice_President_1" />Vice President 1 
    <input type="radio" name="radio_array[]" value="VP2" name="Vice_President_2" />Vice President 2 
    </form> 
</div> 



<p></p><p></p> 
<div class="section"> 
    <form> 
    <h3><strong>Secretary General:</strong></h3> 
    <input type="radio" name="radio_array[]" value="SecGen1" name="Secretary_General_1" />Secretary General 1 
    <input type="radio" name="radio_array[]" value="SecGen2" name="Secretary_General_2" />Secretary General 2 
    </form> 
</div> 


<p></p><p></p> 
<div class="section"> 
    <form> 
    <h3>Director of Finance:</h3> 
    <input type="radio" name="radio_array[]" value="FinSec1" name="Finance_1" />Director of Finance 1 
    <input type="radio" name="radio_array[]" value="FinSec2" name="Finance_2" />Director of Finance 2 
    </form> 
</div> 


<p></p><p></p> 
<div class="section"> 
    <form> 
    <h3>Director of Software:</h3> 
    <input type="radio" name="radio_array[]" value="Software1" name="Software_1" />Director of Software 1 
    <input type="radio" name="radio_array[]" value="Software2" name="Software_2" />Director of Software 2 
    </form> 
</div> 


<p></p><p></p> 
<div class="section"> 
    <form> 
    <h3>Assistant Secretary General:</h3> 
    <input type="radio" name="radio_array[]" value="AssSecGen1" name="Assist_Sec_Gen_1" />Assistant Secretary General 1 
    <input type="radio" name="radio_array[]" value="AssSecGen2" name="Assist_Sec_Gen_2" />Assistant Secretary General 2 
    </form> 
</div> 


<p></p><p></p> 
<div class="section"> 
    <form> 
    <h3>Director of Information:</h3> 
    <input type="radio" name="radio_array[]" value="Info1" name="Info_1" />Director of Information 1 
    <input type="radio" name="radio_array[]" value="Info2" name="Info_2" />Director of Information 2 
    </form> 
</div> 


<p></p><p></p> 
<div class="section"> 
    <form> 
    <h3>Director of Welfare:</h3> 
    <input type="radio" name="radio_array[]" value="Welfare1" name="Welfare_1" />Director of Welfare 1 
    <input type="radio" name="radio_array[]" value="Welfare2" name="Welfare_2" />Director of Welfare 2 
    </form> 
</div> 

<p></p><p></p> 
<div class="section"> 
    <form> 
    <h3>Director of Sports:</h3> 
    <input type="radio" name="radio_array[]" value="Sport1" name="Sports_1" />Director of Sport 1 
    <input type="radio" name="radio_array[]" value="Sport2" name="Sports_2" />Director of Sport 2 
    </form> 
</div> 


<p></p><p></p> 
<div class="section"> 
    <form> 
    <h3>Director of protocol:</h3> 
    <input type="radio" name="radio_array[]" value="Protocol1" name="Protocol_1" />Director of Protocol 1 
    <input type="radio" name="radio_array[]" value="Protocol2" name="Protocol_2" />Director of Protocol 2 
    </form> 
</div> 



<p></p><p></p> 
<div class="section"> 
    <form> 
    <h3>Financial Secretary</h3> 
    <input type="radio" name="radio_array[]" value="FinSec1" name="Fin_Sec_1" />Financial Secretary 1 
    <input type="radio" name="radio_array[]" value="FinSec2" name="Fin_Sec_2" />Financial Secretary 2 
    </form> 
</div> 

</div> 
<p></p> 
<input type="submit" name="submit" /> 

</body> 

</html> 

データベースコネクタは、次のとおりです。

<?php 
$servername = "localhost"; 
$username = "root"; 
$password = "5050"; 
$dbname = "election"; 

// Create connection 
$conn = mysqli_connect($servername, $username, $password, $dbname); 

// Check connection 
if (!$conn) { 
die("Connection failed: " . mysqli_connect_error()); 
} 


$sqli = "INSERT INTO `election`.`voted` (`Reg_Num`, `President_1`, `President_2`, `Vice_President_1`, `Vice_President_2`, `Secretary_General_1`, `Secretary_General_2`, `Finance_1`, `Finance_2`, `Software_1`, `Software_2`, `Assist_Sec_Gen_1`, `Assist_Sec_Gen_2`, `Info_1`, `Info_2`, `Welfare_1`, `Welfare_2`, `Sports_1`, `Sports_2`, `Protocol_1`, `Protocol_2`, `Fin_Sec_1`, `Fin_Sec_2`) 
VALUES 
('$_POST[Reg_Num]', '$_POST[President_1]', '$_POST[President_2]', '$_POST[Vice_President_1]', '$_POST[Vice_President_2]', '$_POST[Secretary_General_1]', '$_POST[Secretary_General_2]', '$_POST[Finance_1]', '$_POST[Finance_2]', '$_POST[Software_1]', '$_POST[Software_2]', '$_POST[Assist_Sec_Gen_1]', '$_POST[Assist_Sec_Gen_2]', '$_POST[Info_1]', '$_POST[Info_2]', '$_POST[Welfare_1]', '$_POST[Welfare_2]', '$_POST[Sports_1]', '$_POST[Sports_2]', '$_POST[Protocol_1]', '$_POST[Protocol_2]', '$_POST[Fin_Sec_1]', '$_POST[Fin_Sec_2]');"; 

if ($conn->query($sqli) === TRUE) { 
    echo "Voted Successfully"; 
} else { 
    echo "Error: " . $conn->error; 
} 

?> 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Form</title> 
</head> 
<body> 
<title>Form Submitted</title> 
<p></p> 
<p>Thanks for Voting.</p> 
<p></p> 
<p>Please note that you cannot vote two times</p> 
<p></p> 
<a href="registration.php">Another Voter</a><br /> 
</body> 
</html> 

助けてください!

+0

追加の

タグを削除します。 – RJParikh

+0

私は混乱しています。なぜあなたは非常に多くのフォームタグを持っていますか?また、最初のフォームを閉じることもありません。他のすべてのフォームタグを削除し、すべての入力フィールドをレンダリングした後に最初のフォームを閉じてみてください。 –

答えて

0

あなたのフォーム要素がある2名の属性...名= "radio_array []"

更新あなたのINSERTクエリである第一name属性削除:このような

$sqli = "INSERT INTO `election`.`voted` (`Reg_Num`, `President_1`, `President_2`, `Vice_President_1`, `Vice_President_2`, `Secretary_General_1`, `Secretary_General_2`, `Finance_1`, `Finance_2`, `Software_1`, `Software_2`, `Assist_Sec_Gen_1`, `Assist_Sec_Gen_2`, `Info_1`, `Info_2`, `Welfare_1`, `Welfare_2`, `Sports_1`, `Sports_2`, `Protocol_1`, `Protocol_2`, `Fin_Sec_1`, `Fin_Sec_2`) 
VALUES 
('".$_POST['Reg_Num']."', '".$_POST["President_1"]."', '".$_POST["President_2]."', '".$_POST["Vice_President_1"]'"......"; 

を.... また、あなたはそれがformタグ内にある必要があります.....あなたinput type="submit"ボタンはOUTSIDE formのある、SQLインジェクション

+0

質問は提出しません。ユーザーは挿入クエリで問題はありません。 – RJParikh

0

笑のための予防策を取る必要があります。一度にすべての入力フィールドを送信したくない場合を除いて、100ではなく1つのフォームを作成してください。

すべてのフォームには送信ボタンが必要です。それ以外は何も提出しません。

Read this

<form method="post" action="vote_process.php" > 

<div class="section"> 
<strong>Matriculation Number:</strong> 
    <input type="text" size="30" maxlength="16" name="Reg_Num" /><br /> 
</div> 
<p><p></p></p> 

<div class="section"> 
    <h3><strong>President:</strong></h3> 
    <input type="radio" name="radio_array[]" value="Presi_1" name="President_1" />President 1 
    <input type="radio" name="radio_array[]" value="Presi 2" name="President_2" />President 2 
</div> 

<p></p><p></p> 
<div class="section"> 
    <h3><strong>Vice President:</strong></h3> 
    <input type="radio" name="radio_array[]" value="VP1" name="Vice_President_1" />Vice President 1 
    <input type="radio" name="radio_array[]" value="VP2" name="Vice_President_2" />Vice President 2 
</div> 

<p></p><p></p> 
<div class="section"> 
    <h3><strong>Secretary General:</strong></h3> 
    <input type="radio" name="radio_array[]" value="SecGen1" name="Secretary_General_1" />Secretary General 1 
    <input type="radio" name="radio_array[]" value="SecGen2" name="Secretary_General_2" />Secretary General 2 
</div> 

<p></p><p></p> 
<div class="section"> 
    <h3>Director of Finance:</h3> 
    <input type="radio" name="radio_array[]" value="FinSec1" name="Finance_1" />Director of Finance 1 
    <input type="radio" name="radio_array[]" value="FinSec2" name="Finance_2" />Director of Finance 2 
</div> 

<p></p><p></p> 
<div class="section"> 
    <h3>Director of Software:</h3> 
    <input type="radio" name="radio_array[]" value="Software1" name="Software_1" />Director of Software 1 
    <input type="radio" name="radio_array[]" value="Software2" name="Software_2" />Director of Software 2 
</div> 

<p></p><p></p> 
<div class="section"> 
    <h3>Assistant Secretary General:</h3> 
    <input type="radio" name="radio_array[]" value="AssSecGen1" name="Assist_Sec_Gen_1" />Assistant Secretary General 1 
    <input type="radio" name="radio_array[]" value="AssSecGen2" name="Assist_Sec_Gen_2" />Assistant Secretary General 2 
</div> 

<p></p><p></p> 
<div class="section"> 
    <h3>Director of Information:</h3> 
    <input type="radio" name="radio_array[]" value="Info1" name="Info_1" />Director of Information 1 
    <input type="radio" name="radio_array[]" value="Info2" name="Info_2" />Director of Information 2 
</div> 

<p></p><p></p> 
<div class="section"> 
    <h3>Director of Welfare:</h3> 
    <input type="radio" name="radio_array[]" value="Welfare1" name="Welfare_1" />Director of Welfare 1 
    <input type="radio" name="radio_array[]" value="Welfare2" name="Welfare_2" />Director of Welfare 2 
</div> 

<p></p><p></p> 
<div class="section"> 
    <h3>Director of Sports:</h3> 
    <input type="radio" name="radio_array[]" value="Sport1" name="Sports_1" />Director of Sport 1 
    <input type="radio" name="radio_array[]" value="Sport2" name="Sports_2" />Director of Sport 2 
</div> 

<p></p><p></p> 
<div class="section"> 
    <h3>Director of protocol:</h3> 
    <input type="radio" name="radio_array[]" value="Protocol1" name="Protocol_1" />Director of Protocol 1 
    <input type="radio" name="radio_array[]" value="Protocol2" name="Protocol_2" />Director of Protocol 2 
</div> 

<p></p><p></p> 
<div class="section"> 
    <h3>Financial Secretary</h3> 
    <input type="radio" name="radio_array[]" value="FinSec1" name="Fin_Sec_1" />Financial Secretary 1 
    <input type="radio" name="radio_array[]" value="FinSec2" name="Fin_Sec_2" />Financial Secretary 2 
</div> 

</div> 
<p></p> 
<input type="submit" name="submit" /> 
</form> <-- close it here 
1

当社のHTMLコードがborkedビットで、これはそれを修正するのに役立つはずです。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Vote</title> 
</head> 

<body> 

<h1>Please note that you only get to vote one time. Look carefully and make a wise choice.</h1> 

<form method="post" action="vote_process.php" > 

<div class="section"> 
<strong>Matriculation Number:</strong> 
    <input type="text" size="30" maxlength="16" name="Reg_Num" /><br /> 
</div> 
<p><p></p></p> 



<div class="section"> 

    <h3><strong>President:</strong></h3> 
    <input type="radio" value="Presi_1" name="President_1" />President 1 
    <input type="radio" value="Presi_2" name="President_2" />President 2 

</div> 

<p></p><p></p> 
<div class="section"> 

    <h3><strong>Vice President:</strong></h3> 
    <input type="radio" value="VP1" name="Vice_President_1" />Vice President 1 
    <input type="radio" value="VP2" name="Vice_President_2" />Vice President 2 

</div> 



<p></p><p></p> 
<div class="section"> 

    <h3><strong>Secretary General:</strong></h3> 
    <input type="radio" value="SecGen1" name="Secretary_General_1" />Secretary General 1 
    <input type="radio" value="SecGen2" name="Secretary_General_2" />Secretary General 2 

</div> 


<p></p><p></p> 
<div class="section"> 

    <h3>Director of Finance:</h3> 
    <input type="radio" value="FinSec1" name="Finance_1" />Director of Finance 1 
    <input type="radio" value="FinSec2" name="Finance_2" />Director of Finance 2 

</div> 


<p></p><p></p> 
<div class="section"> 

    <h3>Director of Software:</h3> 
    <input type="radio" value="Software1" name="Software_1" />Director of Software 1 
    <input type="radio" value="Software2" name="Software_2" />Director of Software 2 

</div> 


<p></p><p></p> 
<div class="section"> 

    <h3>Assistant Secretary General:</h3> 
    <input type="radio" value="AssSecGen1" name="Assist_Sec_Gen_1" />Assistant Secretary General 1 
    <input type="radio" value="AssSecGen2" name="Assist_Sec_Gen_2" />Assistant Secretary General 2 

</div> 


<p></p><p></p> 
<div class="section"> 

    <h3>Director of Information:</h3> 
    <input type="radio" value="Info1" name="Info_1" />Director of Information 1 
    <input type="radio" value="Info2" name="Info_2" />Director of Information 2 

</div> 


<p></p><p></p> 
<div class="section"> 

    <h3>Director of Welfare:</h3> 
    <input type="radio" value="Welfare1" name="Welfare_1" />Director of Welfare 1 
    <input type="radio" value="Welfare2" name="Welfare_2" />Director of Welfare 2 

</div> 

<p></p><p></p> 
<div class="section"> 

    <h3>Director of Sports:</h3> 
    <input type="radio" value="Sport1" name="Sports_1" />Director of Sport 1 
    <input type="radio" value="Sport2" name="Sports_2" />Director of Sport 2 

</div> 


<p></p><p></p> 
<div class="section"> 

    <h3>Director of protocol:</h3> 
    <input type="radio" value="Protocol1" name="Protocol_1" />Director of Protocol 1 
    <input type="radio" value="Protocol2" name="Protocol_2" />Director of Protocol 2 

</div> 



<p></p><p></p> 
<div class="section"> 

    <h3>Financial Secretary</h3> 
    <input type="radio" value="FinSec1" name="Fin_Sec_1" />Financial Secretary 1 
    <input type="radio" value="FinSec2" name="Fin_Sec_2" />Financial Secretary 2 

</div> 

</div> 
<p></p> 
<input type="submit" name="submit" /> 
</form> 
</body> 

</html> 

あなたが一度だけ投票できると指定しているので、同じフォームが2回送信されないようにいくつかの対策を追加することをおすすめします。

また、PHPスクリプトでポストされたデータをデバッグするためにあなたを助けるために、このコードの次のビットは、通常、どのような掲載されています確認することができます:あなたは、あなたのPOSTデータをmysqli_real_escape_stringして準備したいと思うでしょう

<?php 
echo "<pre>"; 
print_r($_POST); 
echo "</pre>; 
?> 

また、挿入前にMYSQL攻撃を防ぐのに役立ちます。

関連する問題