Hi there folks,
I'm trying to insert a record and it's driving me batty.
Here's my query:
$query="INSERT INTO notifications_notifications (title,create_date,end_date,impressions,content,anon_viewable,member_viewable,img_alert,type,allow_override,active) VALUES ('".$title."',NOW(),".$db_expiry.",'".$impressions."','".$content."','".$anon_viewable."','".$member_viewable."','".$img_alert."','".$type."','".$allow_override."','".$active."')";
Here's the query when it's printed out:
INSERT INTO notifications_notifications (title,create_date,end_date,impressions,content,anon_viewable,member_viewable,img_alert,type,allow_override,active) VALUES ('Member Map',NOW(),,'20','<p>Did you know that the site has a <a href=\\"http://www.husaberg.org/membermap.php\\">member map</a>, where you can see where everyone lives and share your own location as well?</p>\r\n\r\n<p>You can also <a href=\\"http://www.husaberg.org/membermap.php?action=preferences\\">choose to be notified</a> when someone places a pin that's near yours.</p>\r\n\r\n<p>Now get out there and find your riding buddy!</p>\r\n','1','1','0','3','1','1')
Here's 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 ''20','<p>Did you know that the site has a <a href=\\"http://www.husaberg.org/me' at line 1
Here's how I'm preparing the values:
// Set a baseline for some empty values.
$db_expiry = '';
$db_impressions = '';
// Grab the form data.
$title = mysql_real_escape_string(substr($_POST['title'], 0, 100));
$content = mysql_real_escape_string(substr($_POST['content'], 0, 5120));
$type = substr($_POST['type'], 0, 1);
if($type == 1){
$expiry = mysql_real_escape_string(substr($_POST['expiry'], 0, 1));
$expiry_uot = mysql_real_escape_string(substr($_POST['expiry_uot'], 0, 6));
if($expiry != '0' AND $expiry_uot != '0'){
$db_expiry = "DATE_ADD(NOW(), INTERVAL ".$expiry." ".$expiry_uot.")";
}
}elseif($type == 3){
$impressions = substr(preg_replace('[\D]', '', $_POST['impressions']), 0, 6);
}
if(ISSET($_POST['active'])){
$active = '1';
}else{
$active = '0';
}
if(ISSET($_POST['anon_viewable'])){
$anon_viewable = '1';
}else{
$anon_viewable = '0';
}
if(ISSET($_POST['member_viewable'])){
$member_viewable = '1';
}else{
$member_viewable = '0';
}
if(ISSET($_POST['img_alert'])){
$img_alert = '1';
}else{
$img_alert = '0';
}
if(ISSET($_POST['allow_override'])){
$allow_override = '1';
}else{
$allow_override = '0';
}
I can't figure out why the URL is breaking the insertion. Could someone point me towards the offender?
Thanks for your time!