Jump to content

Insert Into ... Values ...


dzhax
 Share

Recommended Posts

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

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

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

Edited by dzhax
Link to comment
Share on other sites

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.

Edited by Synook
Link to comment
Share on other sites

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. Edited by dzhax
Link to comment
Share on other sites

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.

Edited by dzhax
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...