private message script not working
Posted: Thu Mar 08, 2012 4:42 pm
I've added a simple pm system on to my localhost recently and while I can send messages successfully, I can't receive them and new messages don't show up in the inbox.
inbox.php
new_message.php
messageck.php
read_message.php
Any insight on why this isn't working is appreciated! The config.php page has the session start and connection to the db.
inbox.php
Code: Select all
<?php
include('config.php');
include('date.php');
$userfinal = $_SESSION['id'];
$get_messages = mysql_query("SELECT message_id FROM messages WHERE
to_user='$userfinal' ORDER BY message_id DESC") or die(mysql_error());
$get_messages2 = mysql_query("SELECT * FROM messages WHERE to_user='$userfinal'
ORDER BY message_id DESC") or die(mysql_error());
$num_messages = mysql_num_rows($get_messages);
// display each message title, with a link to their content
echo '<ul>';
for($count = 1; $count <= $num_messages; $count++)
{
$row = mysql_fetch_array($get_messages2);
//if the message is not read, show "(new)" after the title, else, just show the title.
if($row['message_read'] == 0)
{
echo '<a href="read_message.php?messageid=' . $row['message_id'] .
'">' . $row['message_title'] .
'</a>(New)<br>';
}else{
echo '<a href="read_message.php?messageid=' . $row['message_id'] .
'">' . $row['message_title'] . '</a><br>';
}}
echo '</ul>';
echo '<form name="newmsgfrm" method="post"
action="new_message.php">';
echo '<input type="submit" value="Send a New Message">';
echo '</form>';
echo '<form name="backfrm" method="post" action="index.php">';
echo '<input type="submit" value="Back to Home">';
echo '</form>';
?>Code: Select all
<?php
include('config.php');
include('date.php');
$userfinal = $_SESSION['id'];
$user = $userfinal;
?>
<form name="message" action="messageck.php"
method="post">
Title: <input type="text" name="message_title"> <br />
To: <input type="text" name="message_to"><br />
Message: <br />
<textarea rows="20" cols="50" name="message_content">
</textarea>
<?php
echo '<input type="text" name="message_from"
value="'.$user.'"><br>';
?>
<input type="submit" value="Submit">
</form>Code: Select all
<?php
include('config.php');
include('date.php');
$title = $_POST['message_title'];
$to = $_POST['message_to'];
$content = $_POST['message_content'];
$from = $_POST['message_from'];
$ck_reciever = "SELECT id FROM users WHERE id = '".$to."'";
if( mysql_num_rows( mysql_query( $ck_reciever ) ) == 0 ){
die("The user you are trying to contact doesn't exist. Please go back and try again.<br />
<form name=\"back\" action=\"new_message.php\"
method=\"post\">
<input type=\"submit\" value=\"Try Again\">
</form>
");
}
elseif(strlen($content) < 1){
die("You can't send an empty message!<br>
<form name=\"back\" action=\"new_message.php\"
method=\"post\">
<input type=\"submit\" value=\"Try Again\">
</form>
");
}
elseif(strlen($title) < 1){
die("You must have a Title!<br>
<form name=\"back\" action=\"new_message.php\"
method=\"post\">
<input type=\"submit\" value=\"Try Again\">
</form>
");
}else{
mysql_query("INSERT INTO messages (from_user, to_user, message_title, message_contents) VALUES ('$from','$to','$title','$content')") or die("Error: ".mysql_error());
echo "The Message Was Successfully Sent!";
?>
<form name="back" action="inbox.php"
method="post">
<input type="submit" value="Back to The Inbox">
</form>
<?php
}
?>Code: Select all
<?php
include('config.php');
include('date.php');
$userfinal = $_SESSION['id'];
$messageid = $_GET['message'];
$message = mysql_query("SELECT * FROM messages WHERE message_id = '$messageid' AND
to_user = '$userfinal'");
$message = mysql_fetch_assoc($message);
echo "<h1>Title:
".$message['message_title']."</h1><br><br>";
echo "<h3>From:
".$message['from_user']."<br><br></h3>";
echo "<h3>Message:
<br>".$message['message_contents']."<br></h3>";
echo '<form name="backfrm" method="post" action="inbox.php">';
echo '<input type="submit" value="Back to Inbox">';
echo '</form>';
?>