Jump to content

[SOLVED] SQL Syntax Error for Insert


Nexy

Recommended Posts

Why Hello There! I seem to get an SQL syntax error with this code:

 

<?php

$pmuser = mysql_real_escape_string(addslashes(htmlentities($_POST['pmuser'])));
$subject = mysql_real_escape_string(addslashes(htmlentities($_POST['pmsub'])));
$message = mysql_real_escape_string(addslashes(nl2br(htmlentities($_POST['pmmsg']))));

if($_SESSION['user']) {
$sql = "INSERT INTO pm_inbox(user, from, subject, date, message, status) 
	VALUES('$pmuser', '".$_SESSION['user']."', '$subject', '".date('m-j-Y')."', '$message', 'Unread')";
$res = mysql_query($sql) OR die(mysql_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 'from, subject, date, message, status) VALUES('Nexy', 'Nexy', 'O.O' at line 1

 

One thing I noticed is the error doesn't mention 'user' before 'from' and the values after subject don't come up. Any help would be appreciated!

 

Thank You! :)

Link to comment
Share on other sites

I ran into another problem. :'(

 

<?php

if($_SESSION['user']) {
$sql = "INSERT INTO pm_inbox(user, sender, subject, date, message, status) 
		VALUES('$pmuser', '".$_SESSION['user']."', '$subject', '".date('m-j-Y')."', '$message', 'Unread')";
$res = mysql_query($sql) OR die(mysql_error());

$sqld = "INSERT INTO pm_draft(user, sender, subject, date, message) 
		VALUES('$pmuser', '".$_SESSION['user']."', '$subject', '".date('m-j-Y')."', '$message', 'Unread')";
$resd = mysql_query($sqld) OR die(mysql_error());
}

?>

 

The 2nd sql statement doesn't work. It inserts fine in the first one to pm_inbox, but it doesn't go into pm_draft. Any ideas?

 

Thank You! :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.