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:
<?php
$UserID = intval($_POST['UserID']);
$LastUpdatedFirstname = sprintf($_POST['LastUpdatedFirstname']);
$LastUpdatedLastname = sprintf($_POST['LastUpdatedLastname']);
/********************
*Update
********************/
#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
mysql_query($sql1);
echo mysql_error();
mysql_query($sql2);
echo mysql_error();
?>
If anyone has any suggestions or ideas how to resolve this that would be much appreciated. Thanks.