Jump to content


Photo

"You have an error in your SQL syntax"


  • Please log in to reply
4 replies to this topic

#1 kurtis

kurtis
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 01 September 2006 - 06:19 PM

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:
$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());

does anyone know how to solve this error?

thanks

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 01 September 2006 - 06:34 PM

Can you please post the code that comes before your DB insertion? Thanks.
PHP Ninja

#3 kurtis

kurtis
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 01 September 2006 - 06:40 PM

<?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());
?>

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

#4 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 01 September 2006 - 06:44 PM

well looks like your field names are messed up. Somehwere around to_id.

Are your field names correct?? Check to make sure they are, and any spaces you need to put the field names in ticks "`".

Ray

#5 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 01 September 2006 - 08:41 PM

try to change read to `read`




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users