So I have a problem with viewing messages in my inbox. If I have more than one message, for example, here are the messages listed by ID order:
Testing (this message's id will be 5)
Blahblah (this message's id will be 3)
If I click on Blahblah, it shows up fine. If I click on Testing, it shows the Blahblah message.
Now, I know exactly what is wrong, the script is just pulling the first value that has a message with my name as to_user, but I need it to pull by if the message was directed to me AND by its proper ID so that it shows the right message.
Here is my read_message.php (I believe the problem is here):
Code: Select all
<html>
<head>
<title>Read a Message</title>
</head>
<body>
<?php
include_once 'connect.php';
session_start();
include_once 'logo.php';
?>
<link href="style.css" rel="stylesheet" type="text/css" />
<?php
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
}
else
{
echo "Not Logged in <br><br> <A href='home.php'>Login</a>";
exit;
}
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("Could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
include_once 'statpanel.php';
include_once 'logo.php';
?>
<?php
$updateplayer="update messages set message_read='1' where to_user='$player'";
mysql_query($updateplayer) or die("Could not update player");
$message = mysql_query("SELECT * FROM messages WHERE to_user = '$player'");
$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 "<a href='owlery.php'>Go back to the Owlery</a>";
?>
</body>
</html>
Code: Select all
<html>
<head>
<title>Your Messages</title>
</head>
<body>
<?php
include_once 'connect.php';
session_start();
include_once 'logo.php';
?>
<link href="style.css" rel="stylesheet" type="text/css" />
<?php
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
}
else
{
echo "Not Logged in <br><br> <A href='home.php'>Login</a>";
exit;
}
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("Could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
include_once 'statpanel.php';
include_once 'logo.php';
?>
<?php
// get the messages from the table.
$get_messages = mysql_query("SELECT message_id FROM messages WHERE to_user='$player' ORDER BY message_id DESC") or die(mysql_error());
$get_messages2 = mysql_query("SELECT * FROM messages WHERE to_user='$player' 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'] . '"><font color="#FFE920">' . $row['message_title'] . '</font></a><br>';
}else{
echo '<a href="read_message.php?messageid=' . $row['message_id'] . '">' . $row['message_title'] . '</a><br><br>';
}}
echo '</ul>';
echo '<a href="owlery.php">Go back to the Owlery</a><br><br>';
echo '<a href="index.php">Go back to the Great Hall</a>';
?>
</body>
</html>
I hope you guys know what I'm talking about, I found it kind of difficult to explain

Thanks everyone!