Page 2 of 2
Re: How to get checkbox value and compare with table row val
Posted: Wed Apr 11, 2012 8:05 am
by kwh01
social_experiment wrote:kwh01 wrote:it inserted 2 rows at once. hmm. cannot figured it out why
How many subjects did you select?
perviously is two, but now i get some other error again = =
here is the query i trying to insert the subject number and student ID inserted
but now, no more inserted 2 row per once. it can insert into my table but show me this error.
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
and im trying to select 2 checkbox but it only insert the 1st record into table only
Re: How to get checkbox value and compare with table row val
Posted: Wed Apr 11, 2012 8:15 am
by social_experiment
The syntax for the query seems ok; the column you are inserting into (i'm guessing it will be subjectnumber), is it marked 'unique'?
Re: How to get checkbox value and compare with table row val
Posted: Wed Apr 11, 2012 8:18 am
by kwh01
social_experiment wrote:The syntax for the query seems ok; the column you are inserting into (i'm guessing it will be subjectnumber), is it marked 'unique'?
hmm, nope. i did not set any key for subjectnumber or studentID in table
Re: How to get checkbox value and compare with table row val
Posted: Wed Apr 11, 2012 8:47 am
by social_experiment
Amend the code to the example below and paste the data printed to the browser
Code: Select all
<?php
foreach($_POST['stusubject'] as $subjectnumber)
{
$sql="INSERT INTO $tbl_name(studentID,subjectnumber)VALUES('$_SESSION[stuID]','$subjectnumber')";
echo $sql . '<br />';
/*
$qry = mysql_query($sql);
if (!mysql_query($qry))
{
//die('Error: ' . mysql_error());
echo
}
*/
}
?>
Re: How to get checkbox value and compare with table row val
Posted: Wed Apr 11, 2012 8:47 am
by kwh01
Code: Select all
if (!mysql_query($qry))
{
die('Error: ' . mysql_error());
}
sir, after i removed this line, it works like a charm. omg.
Re: How to get checkbox value and compare with table row val
Posted: Wed Apr 11, 2012 8:51 am
by kwh01
thank you sir for assisting me . finally i can check the checkbox and insert into my database.
thanks alot
Re: How to get checkbox value and compare with table row val
Posted: Wed Apr 11, 2012 9:08 am
by social_experiment
what did you do to solve the issue
Re: How to get checkbox value and compare with table row val
Posted: Wed Apr 11, 2012 11:45 pm
by kwh01
social_experiment wrote:what did you do to solve the issue
Code: Select all
if (!mysql_query($qry))
{
die('Error: ' . mysql_error());
}
Hi social_experiment, i just removed this line and it work perfectly.