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
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!");
}

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.