Hi, I need help for this problem that i'm trying to solve for a while (i'm new in PHP). How do i submit the value into database?
Here's the code:
<form name="Form1" method="POST" action="checkbox.php">
<p><input type="checkbox" name="floor tile"> Floor Tiles</p>
<p><input type="checkbox" name="polished tile"> Polished Tiles</p>
<p><input type="checkbox" name="homogeneous tile"> Homogeneous Tiles</p>
<p><input type="checkbox" name="wall tile"> Wall Tiles</p>
<p><input type="submit" name="submit" value="Submit"></p>
</form>
<?php
$con = mysql_connect("localhost","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
/* show which options were selected */
foreach( $_POST as $key=>$val )
{
if( $key != "Submit" ) {
echo $key.' - '.$val.'<br />';
}
}
/* check how many options were selected */
if( count( $_POST ) > 1 )
{
echo '<p>You have selected too many options.</p>';
}
else
{
/* put your insert query here */
$i<count($_POST['checkbox'] as $value) <--line27
$_POST['checkbox'][$i]
$sql = mysql_query("INSERT (tile ) VALUES ('$value') INTO product_type");
}
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con)
?>
The problem is its showing a parse error which is:
(Parse error: parse error in C:\wamp\www\test\checkbox.php on line 27)
I also need to be able to restrict the user to select not more than one choice. Any help would be greatly appreciated! Thanks!