Jump to content

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