[UPHPU] Checkboxes and MySQL

Nicholas Vettese nvettese at pdistributors.com
Tue Nov 28 11:13:03 MST 2006


This is something I have been working on for some time, and I can't get
an answer from the 101 books, nor google on what I am doing wrong.
Could be me, who knows.  :)
 
I have a form, and on that form are checkboxes.  I am trying to get the
information from the users into the database.  I am not programmer, and
loops make me dizzy, so I was hoping that you may have some information
for me.  Here is my code:
 
<script>
if (isset($_POST['submitted'])) { // Handle the form.
 require_once('mysql_connect-local.php');
 foreach ($test as $m) {
  $query = "INSERT INTO movies (test) VALUES ('$m')";  
  $result = mysql_query ($query) or trigger_error("Query: $query\n<br
/>MySQL Error: " . mysql_error());
 }
}
?>
<h1>Checkbox Testing</h1>
<p>Please tell us which type of movies you like</p>
<form action="movies.php" method="post">
<input type="checkbox" name="test[]" value="vintage" />Vintage<br />
<input type="checkbox" name="test[]" value="sci-fi" />Scince Fiction<br
/>
<input type="checkbox" name="test[]" value="documentary"
/>Documentary<br />
<input type="checkbox" name="test[]" value="comedy" />Comedy<br />
<input type="checkbox" name="test[]" value="family" />Family<br />
<input type="checkbox" name="test[]" value="drama" />Drama<br />
<input type="checkbox" name="test[]" value="adult" />adult<br />
 
<input type="submit" name="submit" value="Submit" />
<input type="hidden" name="hidden" value="TRUE" />
</form>
</script>
 
Thanks in advance for any help with this.
 
Nick


More information about the UPHPU mailing list