PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
<?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>';
?>
Sorry I didn't include this in to the original message- the messages are not showing up in the database, meaning they aren't being properly inserted/stored? But I thought I was doing everything right so I'm rather confused.
mysql_query("INSERT INTO messages (from_user, to_user, message_title, message_contents,
message_date) VALUES ('$from','$to','$title','$content','$time')" OR die('Could not send the message').mysql_error());
You've got a couple closing parentheses in the wrong places.
Thanks! Found the missing parenthesis and fixed it! However now when i click on the message, it shows up blank (even though the message is being stored in the databse, it's just not being properly showed). Also, it still says 'new' even after I click on it. Did I mess something up in the coding? Edited my original post with the new codes.
dyr wrote:However now when i click on the message, it shows up blank (even though the message is being stored in the databse, it's just not being properly showed).
The URL is read_message.php?messageid= but your script looks for $_GET[message].
dyr wrote:Also, it still says 'new' even after I click on it.
Thanks again! I got it working now. My question now is, when it says 'from' it shows the User's ID#. When people send messages they use the user's ID# so that's why it's showing. I'm wondering if I could show both the display name, AND the id# in the 'from' line? ex: Dyr (#1)
What kind of editing to the codes would I need to do?
Hi, using something from the mySQL side doesn't seem to work for what I'd like to accomplish. How could I produce the same effect, but running it through the php-code side? How would I be able to get the callname from the current session? (since I use the session ID# set as the 'from' user)