Jump to content

retireving checkbox value from database


poleposters

Recommended Posts

Hi,

 

I have a checkbox form where the user can update their selections

 

How do I display which checkboxes have been previously checked?

 

Below is the code I have so far

 

<?php

if(isset($_POST['submit']))
{

$fields=$_POST["fields"];

$n=count($fields);
   echo "User chose $n items from the list.<br>\n";
   for($i=0;$i<$n;$i++)
   {
   $query="INSERT INTO specialties (specialty_id,business_id,specialty) VALUES ('','1','$kink[$i].')";
   $result=mysql_query($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
   }




}
else
{


print"
<form id=\"specialties\" action=\"specialties.php\" method=\"post\">

<fieldset class=\"specialties\">

<label for=\"age\">Age</label>
<input type=\"checkbox\" name=\"fields[]\" value=\"age\">

<label for=\"eyes\">Eye colour</label>
<input type=\"checkbox\" name=\"fields[]\" value=\"eyes\">

<label for=\"hair\">Hair colour</label>
<input type=\"checkbox\" name=\"fields[]\" value=\"hair\">

<label for=\"bust\">Bust size</label>
<input type=\"checkbox\" name=\"fields[]\" value=\"bust\">

<label for=\"hips\">Hip</label>
<input type=\"checkbox\" name=\"fields[]\" value=\"hips\">

<label for=\"waist\">Waist</label>
<input type=\"checkbox\" name=\"fields[]\" value=\"waist\">

</fieldset>

<fieldset class=\"specialties\">

<label for=\"age\">Age</label>
<input type=\"checkbox\" name=\"fields[]\" value=\"1\">

<label for=\"eyes\">Eye colour</label>
<input type=\"checkbox\" name=\"fields[]\" value=\"2\">

<label for=\"hair\">Hair colour</label>
<input type=\"checkbox\" name=\"fields[]\" value=\"3\">

<label for=\"bust\">Bust size</label>
<input type=\"checkbox\" name=\"fields[]\" value=\"4\">

<label for=\"hips\">Hip</label>
<input type=\"checkbox\" name=\"fields[]\" value=\"5\">

<label for=\"waist\">Waist</label>
<input type=\"checkbox\" name=\"fields[]\" value=\"6\">




</fieldset>



<input type=\"submit\" class=\"continue\" name=\"submit\" value=\" \" />
</form>
";}
?>

 

Also when updating the database, I think I need to delete all the records in the database for that user before I insert the new choices. Is this the best way to go about it?

 

Link to comment
https://forums.phpfreaks.com/topic/126376-retireving-checkbox-value-from-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.