SQL error caused, I think, by some JS / jQuery

This is an odd one - basically I have a little bit of PHP looping some checkboxes on a page, and on the next page these are written to a database table. This all works just fine… until I introduce some jQuery to style the checkboxes and now I get the 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 ‘’ at line 1

Which doesn’t really help me, especially as I know it works without the jQuery to style the checkboxes.

The code displaying the checkboxes looks like this:

//Display the checkbox
echo "<td width=\"2%\">";
echo "<div class=\"skin skin-square\"><br><input type=\"checkbox\" class=\"tickbox_".$row_type."\"";
if (in_array($keyword['ActivityID'],$user_activities_it)) { echo " checked"; }
echo " name=\"ckbox[".$keyword['ActivityID']."]\" id=\"ckbox[".$keyword['ActivityID']."]\"><br></div>";
echo "</td>\n";

And the code to insert the records looks like this:

$UserID = intval($_POST['UserID']);
$LastUpdatedFirstname = sprintf($_POST['LastUpdatedFirstname']);
$LastUpdatedLastname = sprintf($_POST['LastUpdatedLastname']);


#sql string

//Delete old profile

$sql1 = "DELETE FROM user_activities_it WHERE UserID='$UserID'";

//Enter new profile

$sql2 = "INSERT INTO user_activities_it (UserID, LastUpdatedFirstname, LastUpdatedLastname, ActivityID) VALUES ";

$ck = $_POST['ckbox'];

//loops though the profiles adding the the insert string each profile row

foreach ($ck As $GetIndex => $GetValue){
if ($GetValue=='on'){
$sql2 .= "('$UserID', '$LastUpdatedFirstname', '$LastUpdatedLastname', '$GetIndex'), ";

//trims the end ,

$sql2 = rtrim($sql2," ,") ;

//select db

mysql_select_db($database_myConnection, $myConnection);

//deletes and inserts data


echo mysql_error();


echo mysql_error();


If anyone has any suggestions or ideas how to resolve this that would be much appreciated. Thanks.

Echo $sql1 and $sql2 and see if the queries are correct?
Also do a var_dump of $_POST to see if the form values are arriving as expected? If the jquery causes this, the problem probably lies there.

Just to say I found an alternative script to style the checkboxes, which works great and didn’t cause the same issue.

If anyone happens on this looking for something similar, I can recommend it:


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.