Jump to content

"You have an error in your SQL syntax"


kurtis

Recommended Posts

im making a messaging system, very simple and easy but i get this 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 'read, sender_ip, text, time) VALUES('0', 'dthdjh', '6', '7', '0', '127.0.0.1', '' at line 1"

the code for the mysql query is:
[code]
$query = mysql_query("INSERT INTO messages (id, subject, sender_id, to_id, read, sender_ip, text, time) VALUES('$msg_id', '$subject', '$id', '$to_id', '$read', '$ip', '$message', now())") or die (mysql_error());
[/code]

does anyone know how to solve this error?

thanks
Link to comment
https://forums.phpfreaks.com/topic/19396-you-have-an-error-in-your-sql-syntax/
Share on other sites

[code]
<?php
session_start();
include ('db.php');
$to = $_POST['to'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$id = $_SESSION['id'];
if ((!$to) || (!$subject) || (!$message)){
echo 'You did not supply the following needed infomation<br>';
if (!$to){
echo 'username-We need to know who the message is going to!<br>';
}
if (!$subject){
echo 'subject-You need a subject!<br>';
}
if (!$message){
echo 'message-Currect me if im wrong but you are trying to send a message so obviously you need a message!<br>';
}
include ('message.php');
exit();
}
$id_get = mysql_query("SELECT * FROM users WHERE username='$to'") or die (mysql_error());
$to_id = mysql_fetch_array($id_get);
$no_id = mysql_num_rows($id_get);
if($no_id <1){
echo 'the user isnt in our database<br>';
include ('message.php');
exit();
}
$to_id = $to_id['id'];
$msg_id = mysql_insert_id();
$ip = getenv('REMOTE_ADDR');
$read = '0';

$query = mysql_query("INSERT INTO messages (id, subject, sender_id, to_id, read, sender_ip, text, time) VALUES('$msg_id', '$subject', '$id', '$to_id', '$read', '$ip', '$message', now())") or die (mysql_error());
?>
[/code]

if the error is something simple slap me real hard! lol

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.