Jump to content

PHP Won't Display


Stalingrad

Recommended Posts

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();
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/120739-php-wont-display/
Share on other sites

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"

Link to comment
https://forums.phpfreaks.com/topic/120739-php-wont-display/#findComment-622242
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.