Stalingrad Posted August 21, 2008 Share Posted August 21, 2008 Hello. I've programmed a very simple Personal Messaging System for my website, and it works fine, except when you go to view the actual message, it won't display it, it displays blank. I've included my code below. Any help is appreciated, thank you in adcance! =] inbox.php: <?php session_start(); include("config.php"); if($_SESSION['username'] == "" || $_SESSION['password'] == "") { notloggedin(); } if($_SESSION['username'] != "" && $_SESSION['password'] != "") { start(); $title = "<font size=6>Inbox</font>"; $action = $_GET['action']; if($action != "compose" && $action != "view" && $action != "delete" && $action != "reply") { echo "$title<br><br><a href=?action=compose>Compose</a><br><br><table border=\"1\" bordercolor=\"black\" cellpadding=\"10\" cellspacing=\"0\" height=\"24px\" width=\"100%\"><tr><td><b><center>From</center></b></td><td><b><center>Subject</center></b></td><td><center><b>Status</b></center></td></tr>"; $messages = mysql_query("SELECT * FROM messages WHERE userto='$username' ORDER BY id ASC"); while($inbox = @mysql_fetch_array($messages)) { $message_id = mysql_query("SELECT id FROM messages WHERE subject='$showsubject'"); $mid = $inbox['id']; $meid = $_GET['id']; $showfrom = $inbox['userfrom']; $showsubject = $inbox['subject']; $showstatus = $inbox['status']; echo "<tr><td><center><a href=search.php?username=$showfrom>$showfrom</center></td><td><center><a href=inbox.php?action=view&id=$mid>$showsubject</a></center></td><td><center>$showstatus</center></td></tr>"; } echo "</table>"; } if($action == "compose") { $ssubject = $_POST['subject']; $userto = $_POST['userto']; $sbody = $_POST['body']; $send = $_POST['send']; $datenow = date('l, F jS, Y'); if(!isset($send)) { echo "<font size=6>Compose</font><br><br><a href=?action=compose>Compose</a><br><br><table border=\"1\" bordercolor=\"black\" cellpadding=\"5\" cellspacing=\"0\" height=\"100%\" width=\"440px\"><tr><td>"; ?><html><form action="<?php echo "$PHP_SELF"; ?>" method="POST">Subject: <input type="text" name="subject"> To: <input type="text" name="userto"></td></tr><tr><td><textarea name="body" cols="50" rows="14"></textarea></td></tr></table><br><br><input type="submit" name="send" value="Send Message"></form></html><?php } if(isset($send)) { if($ssubject == "" || $userto == "" || $sbody == "" ) { echo "<font size=6>Inbox - Compose</font><br><br><a href=?action=compose>Compose</a><br><br><font color=red>Error! Please Fill out the Entire Form.</font><br><br><table border=\"1\" bordercolor=\"black\" cellpadding=\"5\" cellspacing=\"0\" height=\"100%\" width=\"440px\"><tr><td>"; ?><html><form action="<?php echo "$PHP_SELF"; ?>" method="POST">Subject: <input type="text" name="subject"> To: <input type="text" name="to"></td></tr><tr><td><textarea name="body" cols="50" rows="14"></textarea></td></tr></table><br><br><input type="submit" name="send" value="Send Message"></form></html><?php } $checkto = mysql_num_rows(mysql_query("SELECT id FROM users WHERE username='$userto'")); if($checkto == "0") { echo "<font size=6>Inbox - Compose</font><br><br><a href=?action=compose>Compose</a><br><br><font color=red>Error! That User doesn't Exist.</font><br><br><table border=\"1\" bordercolor=\"black\" cellpadding=\"5\" cellspacing=\"0\" height=\"100%\" width=\"440px\"><tr><td>"; ?><html><form action="<?php echo "$PHP_SELF"; ?>" method="POST">Subject: <input type="text" name="subject"> To: <input type="text" name="userto"></td></tr><tr><td><textarea name="body" cols="50" rows="14"></textarea></td></tr></table><br><br><input type="submit" name="send" value="Send Message"></form></html><?php } if($ssubject != "" && $userto != "" && $checkto >= "1" && $sbody != "") { mysql_query("INSERT INTO messages (userto, userfrom, subject, body, datesent, status) VALUES ('$userto', '$username', '$ssubject', '$sbody', '$datenow', 'Unread')") or die(mysql_error()); echo "<font size=6>Inbox - Compose</font><br><br><a href=inbox.php>Inbox</a> | <a href=?action=compose>Compose</a><br><br><font color=green>Success! Your Message has been Sent.</font><br>"; } } if($action == "view") { $messages_query = mysql_query("SELECT * FROM messages WHERE id='$_GET[id]'"); while($showit = mysql_fetch_array($messages_query)) { $user_from = $showit['userfrom']; $subject_is = $showit['subject']; $body_is = $showit['body']; } echo "<font size=6>Inbox - View</font><br><br><a href=?action=compose>Compose</a> | <a href=inbox.php>Inbox</a><br><br><table border=\"1\" bordercolor=\"black\" height=\"100%\" width=\"440px\" cellpadding=\"5\" cellspacing=\"0\"><tr><td>Subject: $subject_is From: $user_from</td></tr><tr><td>$body_is</td></tr></table><br>"; } stop(); } } ?> Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 21, 2008 Share Posted August 21, 2008 a page showing up blank is often a sign of a parse error, but php is being tight-lipped about the whole affair. try putting these lines at the top: ini_set('display_errors', 'On'); error_reporting(E_ALL); and see what comes back. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted August 21, 2008 Share Posted August 21, 2008 if you indent your code, you'll see that code in this if will NEVER be executed: if($action == "view") { // This will never be true Quote Link to comment Share on other sites More sharing options...
Stalingrad Posted August 21, 2008 Author Share Posted August 21, 2008 I don't understand. How do I make it so that it could be true? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted August 21, 2008 Share Posted August 21, 2008 your brackets are off. indent your code and you'll see how that IF is inside another IF. if the one on the outside is TRUE, then the other one is automatically FALSE. i indented part of your code to find the problem: if($action == "compose") { $ssubject = $_POST['subject']; $userto = $_POST['userto']; $sbody = $_POST['body']; $send = $_POST['send']; $datenow = date('l, F jS, Y'); if(!isset($send)) { echo "<font size=6>Compose</font><br><br><a href=?action=compose>Compose</a><br><br><table border=\"1\" bordercolor=\"black\" cellpadding=\"5\" cellspacing=\"0\" height=\"100%\" width=\"440px\"><tr><td>"; ?><html><form action="<?php echo "$PHP_SELF"; ?>" method="POST">Subject: <input type="text" name="subject"> To: <input type="text" name="userto"></td></tr><tr><td><textarea name="body" cols="50" rows="14"></textarea></td></tr></table><br><br><input type="submit" name="send" value="Send Message"></form></html><?php } if(isset($send)) { if($ssubject == "" || $userto == "" || $sbody == "" ) { echo "<font size=6>Inbox - Compose</font><br><br><a href=?action=compose>Compose</a><br><br><font color=red>Error! Please Fill out the Entire Form.</font><br><br><table border=\"1\" bordercolor=\"black\" cellpadding=\"5\" cellspacing=\"0\" height=\"100%\" width=\"440px\"><tr><td>"; ?><html><form action="<?php echo "$PHP_SELF"; ?>" method="POST">Subject: <input type="text" name="subject"> To: <input type="text" name="to"></td></tr><tr><td><textarea name="body" cols="50" rows="14"></textarea></td></tr></table><br><br><input type="submit" name="send" value="Send Message"></form></html><?php } $checkto = mysql_num_rows(mysql_query("SELECT id FROM users WHERE username='$userto'")); if($checkto == "0") { echo "<font size=6>Inbox - Compose</font><br><br><a href=?action=compose>Compose</a><br><br><font color=red>Error! That User doesn't Exist.</font><br><br><table border=\"1\" bordercolor=\"black\" cellpadding=\"5\" cellspacing=\"0\" height=\"100%\" width=\"440px\"><tr><td>"; ?><html><form action="<?php echo "$PHP_SELF"; ?>" method="POST">Subject: <input type="text" name="subject"> To: <input type="text" name="userto"></td></tr><tr><td><textarea name="body" cols="50" rows="14"></textarea></td></tr></table><br><br><input type="submit" name="send" value="Send Message"></form></html><?php } if($ssubject != "" && $userto != "" && $checkto >= "1" && $sbody != "") { mysql_query("INSERT INTO messages (userto, userfrom, subject, body, datesent, status) VALUES ('$userto', '$username', '$ssubject', '$sbody', '$datenow', 'Unread')") or die(mysql_error()); echo "<font size=6>Inbox - Compose</font><br><br><a href=inbox.php>Inbox</a> | <a href=?action=compose>Compose</a><br><br><font color=green>Success! Your Message has been Sent.</font><br>"; } } if($action == "view") { // WON'T HAPPEN HERE. AT THIS POINT, WE ALREADY KNOW THAT $action == "compose" Quote Link to comment Share on other sites More sharing options...
Stalingrad Posted August 21, 2008 Author Share Posted August 21, 2008 Okay. Thank you for pointing this out. How do I fix it so that it will work? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted August 21, 2008 Share Posted August 21, 2008 make it so that the second IF statement is OUTSIDE the first one. close the curly bracket on the first one. indent your code so all IF's are lined up on the left side. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.