Jump to content

Sending A User A Message


White_Lily

Recommended Posts

Hi, I am trying build a system in which users can send messages to eachother.

 

The problem im having is that the script is having problems inserting the message into the database and i cant figure out why.

 

Here is the code form that the user fills out:

 

<?php
echo '<div id="pronav">';
echo '<ul>';
echo '<li><p>Nav to go here.</p></li>';
echo '</ul>';
echo '<div class="clear"></div>';
echo '</div>';
echo '<img src="'.$GLOBALS["nav"].'images/vertical-rule.png" />';

echo '<p>'.$u.'</p>';

echo '<form action="" method="POST">';
echo '<table border="0" style="width:auto;">';
if(!empty($senderr)){
echo '<tr>';
echo '<td colspan="2"><div class="error">Error: '.$senderr.'</div></td>';
echo '</tr>';
}if(!empty($sendpass)){
echo '<tr>';
echo '<td colspan="2"><div class="pass">Success: '.$sendpass.'</div></td>';
echo '</tr>';
}
echo '<tr>';
echo '<td>To:</td>';
echo '<td><input type="text" name="sendto" id="sendto" class="input" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td align="top">Subject:</td>';
echo '<td><input type="text" name="sendsubject" class="input" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Message:</td>';
echo '<td><textarea name="writemsg" id="sendmsg" class="input" style="height:200px;"></textarea></td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan="2"><input style="float:right;" type="submit" name="sendmsg" class="buttons" value="Send" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
?>

 

Here is the script that inserts the message:

 

//Send Message
$sendmsg = $_POST["sendmsg"];
$to = $_POST["sendto"];
$subject = $_POST["sendsubject"];
$message = $_POST["writemsg"];


if(!empty($sendmsg)){
if(empty($to) || empty($message)){
$senderr = "Please fill out the needed fields in order to send a message. (To: & Message:)";
}else{
$date = date('Y/m/d H:i:s', time());

$putmsg = insert("messages", "id, title, content, to, from, date", "1, '$subject', '$message', '$to', '$u', '$date'");

if($putmsg){
$sendpass = "You have successfully sent your friend a message.";
}else{
$senderr = "Failed to send message to your friend. Please try again later.<br><br>".mysql_error();
}
}
}

 

Here is the error I am recieving:

 

Error: Failed to send message to your friend. Please try again later.

 

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, date) VALUES (1, 'Testing Subject', 'Testing message', 'White_Lily', '' at line 1

 

Any help would be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/270414-sending-a-user-a-message/
Share on other sites

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.