Inserting and Retrieving Checkbox data from mySQL with PHP
Posted: Sat Aug 24, 2002 11:52 am
I am attempting to put in some checkbox info and pull out the values without much success. I have worked with text info just fine in the past and it goes in and comes out fine for me with the example below, however the checkbox info does not display anything.
Checkbox field:
My insert:
I use phpmyAdmin and can see the years app field listed as "Array".
My query to pull it out:
Any help here is appreciated.
Thanks in advance.
Checkbox field:
Code: Select all
<tr>
<td colspan="1" class="regularright">
Years Applicable:
</td>
<td colspan="6" class="regular">
<input type="checkbox" name="yearsappї]" value="1989"> 1989
<input type="checkbox" name="yearsappї]" value="1990"> 1990
<input type="checkbox" name="yearsappї]" value="1991"> 1991
<input type="checkbox" name="yearsappї]" value="1992"> 1992
<input type="checkbox" name="yearsappї]" value="1993"> 1993
<input type="checkbox" name="yearsappї]" value="1994"> 1994
<input type="checkbox" name="yearsappї]" value="1995"> 1995
</td>
</tr>Code: Select all
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$sql = "INSERT INTO parts (partnumber, partdescription, yearsapp) VALUES ('$partnumber','$partdescription','$yearsapp')";
$result = mysql_query($sql);My query to pull it out:
Code: Select all
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM parts";
$result = mysql_query($query) or die("Invalid query");
$num_results = mysql_num_rows($result);
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
if ($i % 2)
{
echo "<tr bgcolor="E2E2EB"><td valign="top" class="regular">".stripslashes($rowї"partnumber"]); // partnumber
}
else
{
echo "<tr bgcolor="B8B8CE"><td valign="top" class="regular">".stripslashes($rowї"partnumber"]); // partnumber
}
echo "</td><td valign="top" class="regular">".stripslashes($rowї"partdescription"]);
echo "</td><td valign="top" class="regular">".stripslashes($rowї"yearsapp"]);
}Thanks in advance.