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
https://forums.phpfreaks.com/topic/113337-solved-sql-syntax-error-for-insert/
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! :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.