We help IT Professionals succeed at work.
Get Started

PHP / HTML Form Processing

Bryan_123
Bryan_123 asked
on
310 Views
Last Modified: 2013-12-12
I have a form that queries a mysql database and prepopulates each <td> through a while($row = mysql_fetch_array( $result )) loop.

10 items are populated.

The desired behavior is that if the checkbox is checked it will insert those into a mysql database table called 'unit_citations_usa' or if none are checked it will do nothing.

This is the form code:

<td width="10">
<FORM METHOD="POST" ACTION="citation_edit_process.php">
<input type="checkbox" name="Citation_ID[]" value="'.$row['Citation_ID'].'" UNCHECKED/>
</td>
<td width="10">
<input type="hidden" name="Citation_Pic[]"><img src="'.$row['Citation_Pic'].'">
 </td>
 <td width="430">
 <input type="hidden" name="Name[]" value="'.$row['Name'].'"/>
 '.$row['Name'].'
</td>

in citation_edit_process i am calling (just practicing with name insert for now) the following, which inserts all 10, not just the ones checked or even if checkboxes are left blank:

foreach($_POST['Name'] as $Citation_Name) {
 if ($Citation_Name !=''){
  mysql_query("INSERT INTO tab_unit_citations_usa (Name) VALUES ('$Citation_Name') ") or die("Your Error " . mysql_error());  
 
 echo "success";
 }

}
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE