php - My form isn't submitting

908

Solution:

our HTML code is a bit borked there, this should help fix it up.

<!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 >
<strong>Matriculation Number:</strong> 
 <input type="text" size="30" maxlength="16" name="Reg_Num" /><br />
</div>
<p><p></p></p>



<div >

  <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 >

  <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 >

  <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 >

  <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 >

  <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 >

  <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 >

  <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 >

  <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 >

  <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 >

  <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 >

  <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>

As you've indicated that you can only vote one time I'd recommend adding some measures to prevent the same form being submitted twice.

Also, to help you to debug the Posted Data in the PHP script, this next bit of code usually helps to check what's being posted:

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

You'll want to mysqli_real_escape_string and prepare your POST data also prior to insertion to help prevent MYSQL attacks.

699

Answer

Solution:

Your form element has two name attribute... remove 1st name attribute which is name="radio_array[]"

update your insert query:

$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"]'"......"; 

like this.... Also you should take precaution for sql injection

547

Answer

Solution:

lol, yourinput type="submit" button is OUTSIDE of theform..... it should be inside theform tag. Also make just one form instead of 100, except when you don't want to submit all input fields at once.

Remember that every form needs an submit button. Or else It will not submit anything.

Read this

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

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

<div >
  <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 >
  <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 >
  <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 >
  <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 >
  <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 >
  <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 >
  <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 >
  <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 >
  <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 >
  <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 >
  <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

People are also looking for solutions to the problem: php - How to toggle elements with javascript

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.