Page 1 of 1

CheckBox Problem[Help] - Cannot insert to database

Posted: Mon Jun 02, 2008 11:48 pm
by joola
Hi, I`m newbie in php. I have this script, its no error. But no variabel was input into the database. Please Help.

This is the script :
<?
$id = $_POST['id1'];
$id2 = $_POST['id2'];
$sql = "INSERT INTO `mychoice` (`cek1`,`cek2`) VALUES ('".$id."','".$id2."')";
?>
<html>
<body>
<form action="cek.php" name="frm1" id="frm1" method="get">
<input name="id1" id="id1" type="checkbox" value="1">Test
<input name="id2" id="id2" type="checkbox" value="2">Test2
<label>
<input type="submit" name="Submit" value="Submit">
</label>
</form>
</body>
</html>

Re: CheckBox Problem[Help] - Cannot insert to database

Posted: Tue Jun 03, 2008 7:00 pm
by califdon
joola wrote:Hi, I`m newbie in php. I have this script, its no error. But no variabel was input into the database. Please Help.

This is the script :
<?
$id = $_POST['id1'];
$id2 = $_POST['id2'];
$sql = "INSERT INTO `mychoice` (`cek1`,`cek2`) VALUES ('".$id."','".$id2."')";
?>
<html>
<body>
<form action="cek.php" name="frm1" id="frm1" method="get">
<input name="id1" id="id1" type="checkbox" value="1">Test
<input name="id2" id="id2" type="checkbox" value="2">Test2
<label>
<input type="submit" name="Submit" value="Submit">
</label>
</form>
</body>
</html>
In your form, you set the method to "GET", but when you look for the variables you are looking at the "POST" array. Change one or the other.

Re: CheckBox Problem[Help] - Cannot insert to database

Posted: Tue Jun 03, 2008 7:56 pm
by nowaydown1
In addition to what califdon mentioned, you're building a string with your SQL query, but I don't see any code to actually execute the query (mysql_query).

Re: CheckBox Problem[Help] - Cannot insert to database

Posted: Tue Jun 03, 2008 8:15 pm
by califdon
nowaydown1 wrote:In addition to what califdon mentioned, you're building a string with your SQL query, but I don't see any code to actually execute the query (mysql_query).
Oops! I should have caught that, but I didn't! :oops: Thanks, nowaydown1.