dzhax Posted August 18, 2009 Share Posted August 18, 2009 I'm making a internal message system that runs through my mysql database. It is sending correctly from the form but it does not seem to work when it comes to sending to the database. Here is what i have. <?php//error_reporting(0);$msgTo = $_GET['msgTo'];$msgFrom = $_GET['msgFrom'];$msgSubject = $_GET['msgSubject'];$msgBody = $_GET['msgBody'];$important = $_GET['important'];$debug = '1';if ($important == 'on'){$important = '1';} else {$important = '0';}if (!$debug){ echo 'To: ' . $msgTo . '<br />'; echo 'From: ' . $msgFrom . '<br />'; echo 'Important: '. $important . '<br />'; echo 'Subject: ' . $msgSubject . '<br />'; echo 'Body:<br />' . $msgBody;}else{ include '../connect.php'; $sendmessage = mysql_query("INSERT INTO `website`.`messagecenter` (`id` ,`to` ,`from` ,`important` ,`subject` ,`body` ,`read`)VALUES (NULL , '" . $msgTo . "', '" . $msgFrom . "', '" . $important . "', '" . $msgSubject . "', '" . $msgBody . "', '0'", $con); if (!$sendmessage){ die('Unable to send message try again later... - Error: 2'); } else { die('Message sent successfully...'); } mysql_close($con);}?> When I run it it gives me the die('Unable to send message try again later... - Error: 2');Meaning that it can connect to the database it just can't send the data to it.I do not see anything wrong with it but maybe a fresh set of eyes can see a mistake. Link to comment Share on other sites More sharing options...
Synook Posted August 18, 2009 Share Posted August 18, 2009 Try echoing mysql_error() to see what the actual problem is. Printing the query string can also help. Link to comment Share on other sites More sharing options...
dzhax Posted August 18, 2009 Author Share Posted August 18, 2009 if (!$sendmessage){ echo mysql_error(); die('<br />Unable to send message try again later... - Error: 2'); } else { die('Message sent successfully...'); } 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 '' at line 1Unable to send message try again later... - Error: 2 I guess there is an error in my mysql query... But i dont see one.BTW how did you get your user title changed to 53 79 6E 6F 6F 6B 0D 0A Link to comment Share on other sites More sharing options...
Synook Posted August 18, 2009 Share Posted August 18, 2009 Echo out the query and see what it actually says. echo "INSERT INTO `website`.`messagecenter` (`id` ,`to` ,`from` ,`important` ,`subject` ,`body` ,`read`)VALUES (NULL , '" . $msgTo . "', '" . $msgFrom . "', '" . $important . "', '" . $msgSubject . "', '" . $msgBody . "', '0'"; Also, don't forget to sanitise your inputs in the end!You can customise your title through "Edit Profile Information" in your control panel. Link to comment Share on other sites More sharing options...
dzhax Posted August 18, 2009 Author Share Posted August 18, 2009 Echo out the query and see what it actually says. echo "INSERT INTO `website`.`messagecenter` (`id` ,`to` ,`from` ,`important` ,`subject` ,`body` ,`read`)VALUES (NULL , '" . $msgTo . "', '" . $msgFrom . "', '" . $important . "', '" . $msgSubject . "', '" . $msgBody . "', '0'"; Also, don't forget to sanitise your inputs in the end!You can customise your title through "Edit Profile Information" in your control panel. INSERT INTO `website`.`messagecenter` (`id` ,`to` ,`from` ,`important` ,`subject` ,`body`) VALUES (NULL , 'Dzhax', 'Louis', '1', 'Test', 'Testin 1 2 3'thats the echo everything seems to send correctly, im starting to think its just my luck.I got the query directly from phpmyadmin. When you insert data it shows the sql statement(s) to preform the same action.and about the user title... they must of taken it out or i dont have enough posts cuz nothin there. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 18, 2009 Share Posted August 18, 2009 I got the query directly from phpmyadmin. When you insert data it shows the sql statement(s) to preform the same action.You missed a closing paren.and about the user title...You need to have a certain number of posts to change it. Link to comment Share on other sites More sharing options...
dzhax Posted August 18, 2009 Author Share Posted August 18, 2009 thanks didnt see that.i figured it was a stupid mistake.anyhelp deleting a record from a table? $sql = "DELETE FROM playersonline WHERE username = '" . $_SESSION['user'] . "'";$deluser = mysql_query($sql, $con); that dosent seem to work either.Its supposed to delete the record that contains the same username as the session user. Link to comment Share on other sites More sharing options...
Synook Posted August 19, 2009 Share Posted August 19, 2009 Any MySQL errors? Link to comment Share on other sites More sharing options...
dzhax Posted August 19, 2009 Author Share Posted August 19, 2009 Sry bout the question... It works now. I moved it lower on down the page and it worked.thank you so much for your help ur awsome. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.