CheckBox Problem[Help] - Cannot insert to database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joola
Forum Newbie
Posts: 8
Joined: Mon May 26, 2008 10:51 pm

CheckBox Problem[Help] - Cannot insert to database

Post 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>
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

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

Post 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.
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

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

Post 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).
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

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

Post 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.
Post Reply