Jump to content

[SOLVED] Messaging system INSERT problem


CoderGenius

Recommended Posts

I've been working on a new online game for a few weeks now, an am in the middle of trying to set up a simple messaging system.

Right now I'm using a simple Table with columns for id, to, from, subject, message, timesent, and read.

my problem is that when i try to insert new messages into the table, they simply never are inserted! I've been checking my syntax for a few days now, an I'm baffled as to why this statement wont work...

 

Here is the portion of the code that isn't working:

if($ready == "Send"){//SEND WAS CLICKED

$check=mysql_query("SELECT * FROM players WHERE id='$to'");
$rowcheck=mysql_fetch_array($check);
if($rowcheck['user'] == ""){
?>
<script language="JavaScript">
<!--
alert("That player does not exist.");
//-->
</script>
<?php
}else{
mysql_query("INSERT INTO messages (to,from,subject,message) VALUES($to,$from,$subject,$message);");
goTown("Message Sent!");
}

}//IF SEND WAS CLICKED

 

The problem is in the insert statement i believe. I've tested the query_fetch_array, and it is in fact returning the correct user that has been specified in the 'to' field. and the function 'goTown' is working, as it is sending the alert that the message was successfully sent.

Any help would be greatly appreciated!

 

PS, if you wanna see the code in action, the game I'm working on is actually online, an playable (except the messaging of course :-[)

heres the URL right now:

http://www.videogamenewz.com/LR

 

Link to comment
https://forums.phpfreaks.com/topic/103070-solved-messaging-system-insert-problem/
Share on other sites

oops... i was trying something out earlier an accidentally forgot to put the quotes back in... but it still doesn't work with them added...

 

heres how the code should actually look:

if($ready == "Send"){//SEND WAS CLICKED

$check=mysql_query("SELECT * FROM players WHERE id='$to'");
$rowcheck=mysql_fetch_array($check);
if($rowcheck['user'] == ""){
?>
<script language="JavaScript">
<!--
alert("That player does not exist.");
//-->
</script>
<?php
}else{
mysql_query("INSERT INTO messages (to,from,subject,message) VALUES('$to','$from','$subject','$message')");
goTown("Message Sent!");
}

Make sure you are connected to the right database. Use mysql_error() to view the errors.

 

mysql_query("INSERT INTO messages (to,from,subject,message) VALUES('$to','$from','$subject','$message')") or die ("Error: ".mysql_error());

 

Can you see any error now?

wow, i cant believe i forgot to put that in there...

 

ok here's the error its generating:

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 'to,from,subject,message) VALUES('1','Quiet Master','TEST','A TEST FOR THE SYSTEM' at line 1

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.