coolcam26 Posted November 26, 2010 Share Posted November 26, 2010 Hi, I have made personal messaging system however I can't reply unless it is to the last message! I think I've messed up the looping somewhere but can you see if you can figure out what's wrong with it? This is the code for the inbox page: <?php require('scripts/top.php'); ?> <title>Spares List | Your Messages</title> <div id='full'> <?php if ($username){ echo "<a href='create_message.php'>Create Message</a> <div id='box'> <b class='corners'> <b class='corners1'><b></b></b> <b class='corners2'><b></b></b> <b class='corners3'></b> <b class='corners4'></b> <b class='corners5'></b></b> <div class='cornersfg'> <div id='top'>Inbox for $username</div> <div id='bottom' style='padding: 10px;'>"; //////////////////////////////////////////////////////////////////////// require('scripts/connect.php'); $query = mysql_query("SELECT * FROM messages WHERE to_user='$username' ORDER BY id DESC"); $numrows = mysql_num_rows($query); if ($numrows > 0){ echo "<form action='delete_message.php' method='POST'>"; echo "<div id='messages'> <div id='leftside'><input type='checkbox' name='selectall'><input type='submit' name='deleteinbox' value='Delete' class='button'></div> <div id='rightside'>Date</div> <div id='center'>Subject and Message</div> <div style='clear: both;'></div> </div>"; while($row = mysql_fetch_assoc($query)){ $msg_id = $row['id']; $msg_to_user = $row['to_user']; $msg_to_id = $row['to_id']; $msg_from_user = $row['from_user']; $msg_from_id = $row['from_id']; $msg_subject = $row['subject']; $msg_content = $row['content']; $msg_date = $row['date']; $msg_from_delete = $row['from_delete']; $msg_to_delete = $row['to_delete']; if (!$msg_to_delete){ echo "<div id='messages'>"; echo "<div id='leftside'> <input type='checkbox' name='cb$msg_id' value='$msg_id'> <a href='profile.php?id=$msg_from_id' target='_blank'>$msg_from_user</a> </div>"; echo "<div id='rightside'>$msg_date</div>"; echo "<div id='center'> <span class='toggle'><a href='#'>$msg_subject</a></span> <div class='hiddenDiv'> <br>$msg_content<br><br> <span class='toggle'><a href='#'>REPLY</a></span> <div class='hiddenDiv'> <form action='reply.php' method='POST'> <input type='hidden' value='$msg_id' name='replyid'> <input type='text' name='replysubject' style='width: 300px;' class='text-box' value='RE: $msg_subject'><br> <textarea name='replycontent' style='width: 298px;' rows='5'></textarea><br><br> <input type='submit' name='replybutton' class='button' value='Reply'> </form> </div> </div> </div>"; echo "<div style='clear: both;'></div>"; echo "</div>"; $num += 1; } } if ($num == 0){ echo "You have no messages in your inbox."; } echo "</form>"; } else echo "You have no messages in your inbox."; //////////////////////////////////////////////////////////////////////// echo "</div> </div> <b class='corners'> <b class='corners5'></b> <b class='corners4'></b> <b class='corners3'></b> <b class='corners2'><b></b></b> <b class='corners1'><b></b></b></b> </div>"; ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// echo "<div id='box'> <b class='corners'> <b class='corners1'><b></b></b> <b class='corners2'><b></b></b> <b class='corners3'></b> <b class='corners4'></b> <b class='corners5'></b></b> <div class='cornersfg'> <div id='top'>Outbox for $username</div> <div id='bottom' style='padding: 10px;'>"; //////////////////////////////////////////////////////////////////////// require('scripts/connect.php'); $query = mysql_query("SELECT * FROM messages WHERE from_user='$username' ORDER BY id DESC"); $numrows = mysql_num_rows($query); if ($numrows > 0){ echo "<form action='delete_message.php' method='POST'>"; echo "<div id='messages'> <div id='leftside'><input type='checkbox' name='selectall'><input type='submit' name='deleteoutbox' value='Delete' class='button'></div> <div id='rightside'>Date</div> <div id='center'>Subject and Message</div> <div style='clear: both;'></div> </div>"; while($row = mysql_fetch_assoc($query)){ $msg_id = $row['id']; $msg_to_user = $row['to_user']; $msg_to_id = $row['to_id']; $msg_from_user = $row['from_user']; $msg_from_id = $row['from_id']; $msg_subject = $row['subject']; $msg_content = $row['content']; $msg_date = $row['date']; $msg_from_delete = $row['from_delete']; $msg_to_delete = $row['to_delete']; if (!$msg_from_delete){ echo "<div id='messages'>"; echo "<div id='leftside'> <input type='checkbox' name='cb$msg_id' value='$msg_id'> <a href='profile.php?id=$msg_from_id' target='_blank'>$msg_from_user</a> </div>"; echo "<div id='rightside'>$msg_date</div>"; echo "<div id='center'> <span class='toggle'><a href='#'>$msg_subject</a></span> <div class='hiddenDiv'> <br>$msg_content<br><br> </div> </div>"; echo "<div style='clear: both;'></div>"; echo "</div>"; $num += 1; } } if ($num == 0){ echo "You have no messages in your outbox."; } echo "</form>"; } else echo "You have no messages in your outbox."; //////////////////////////////////////////////////////////////////////// echo "</div> </div> <b class='corners'> <b class='corners5'></b> <b class='corners4'></b> <b class='corners3'></b> <b class='corners2'><b></b></b> <b class='corners1'><b></b></b></b> </div>"; echo "</div>"; } else echo "<center><h2><font color='red'>You must be logged in to view this page.</font></h2></center>"; require('scripts/bottom.php'); ?> And this is the code for the deleteorsend php file: <?php include("header.inc"); ?> <table border="0" width="100%"><tr><td valign="top" width="800"> <div id="content"> <?php //Start Content $replybtn = $_POST['replybutton']; $inboxbtn = $_POST['deleteinbox']; $outboxbtn = $_POST['deleteoutbox']; if($_SESSION['uid']){ if ($replybtn){ $subject = $_POST['replysubject']; $content = $_POST['replycontent']; $replyid = $_POST['replyid']; if ($subject && $content){ $date = date("M d, Y"); $query = mysql_query("SELECT * FROM messages WHERE content='$content' AND date='$date'"); $numrows = mysql_num_rows($query); if ($numrows == 0){ $query = mysql_query("SELECT * FROM messages WHERE id='$replyid' AND to_user='$username'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ $row = mysql_fetch_assoc($query); $to_id = $row['from_id']; $to_user = $row['from_user']; mysql_query("INSERT INTO messages VALUES ('', '$to_user', '$to_id', '$username', '$userid', '$subject', '$content', '$date', '0', '0')"); echo "Your reply has been sent. <a href='messages.php'>Click here</a> to return to your inbox."; } else echo "No message was sent. An error has occured!!!!"; } else echo "You can NOT resend the same messages."; } else echo "You did not supply a subject and/or message."; } else if($inboxbtn){ $query = mysql_query("SELECT * FROM messages WHERE to_user='$username'"); while ($row = mysql_fetch_assoc($query)){ $msg_id = $row['id']; $value = "cb"."$msg_id"; $checkbox = $_POST[$value]; if ($checkbox){ mysql_query("UPDATE messages SET to_delete='1' WHERE id='$msg_id'"); } } echo "The selected messages have been deleted! <a href='messages.php'>Click here</a> to return to your inbox."; } else if($outboxbtn){ $query = mysql_query("SELECT * FROM messages WHERE from_user='$username'"); while ($row = mysql_fetch_assoc($query)){ $msg_id = $row['id']; $value = "cb"."$msg_id"; $checkbox = $_POST[$value]; if ($checkbox){ mysql_query("UPDATE messages SET from_delete='1' WHERE id='$msg_id'"); } } echo "The selected messages have been deleted! <a href='messages.php'>Click here</a> to return to your inbox."; } else echo "You must click the button!"; } else echo "You must be logged in to do that!"; //End Content ?> </div> </td><td width="250"> <?php include("sidebar.inc"); ?> </td> </table> <?php include("footer.inc"); ?> </div> </div> I hope you can work out what is wrong as I am quite new to php. Thanks in advanced Cameron Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 26, 2010 Share Posted November 26, 2010 I can see that you have nested <form>s. That's invalid markup, and may be causing the problem. Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 26, 2010 Author Share Posted November 26, 2010 I can see that you have nested <form>s. That's invalid markup, and may be causing the problem. What do you mean by nested? How can I fix this? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 26, 2010 Share Posted November 26, 2010 You have structure in there that would result in form tags being like this: <form> some fields . . . <form> fields for second form . . . </form> more fields for the first form . . . </form> Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 26, 2010 Author Share Posted November 26, 2010 <head> <script type="text/javascript" src="includes/jquery.js"></script> <script language="javascript" type="text/javascript"> $(document).ready(function(){ //trigger when clicking element $(".toggle").click(function () { //check visibility if ($(this).next().is(":hidden")) { $(this).next().slideDown("slow"); //slide it down } else { $(this).next().hide(); //hide it } }); }); </script> </head> <?php include("header.inc"); ?> <table border="0" width="100%"><tr><td valign="top" width="800"> <?php echo "<div id='content'>"; echo "<h2 div id='title'>"; echo "Messages"; echo "</h2>"; if($_SESSION['uid']){ echo "<div align='right'><a href='create_message.php'>Create Message  </a></div>"; echo "<h3 div id='subtitle'>"; echo "Inbox"; echo "</h3>"; //Inbox/////////////////////////////////////////////////////////////// $query = mysql_query("SELECT * FROM messages WHERE to_user='$username' ORDER BY id DESC"); $numrows = mysql_num_rows($query); if ($numrows > 0){ echo "<form action='deleteorsend.php' method='POST'>"; echo "<div id='messages'> <div id='leftside'>From...</div> <div id='leftside'><input type='submit' name='deleteinbox' value='Delete' class='button'></div> <div id='rightside'>Date</div> <div id='center'>Subject and Message</div> <div style='clear: both;'></div> </div>"; while($row = mysql_fetch_assoc($query)){ $msg_id = $row['id']; $msg_to_user = $row['to_user']; $msg_to_id = $row['to_id']; $msg_from_user = $row['from_user']; $msg_from_id = $row['from_id']; $msg_subject = $row['subject']; $msg_content = $row['content']; $msg_date = $row['date']; $msg_from_delete = $row['from_delete']; $msg_to_delete = $row['to_delete']; if (!$msg_to_delete){ echo "<div id='messages'>"; echo "<div id='leftside'> <input type='checkbox' name='cb$msg_id' value='$msg_id'> <a href='profile.php?id=$msg_from_id' target='_blank'>$msg_from_user</a> </div>"; echo "<div id='rightside'>$msg_date</div>"; echo "<div id='center'> <span class='toggle'><a href='#'>$msg_subject</a></span> <div class='hiddenDiv'> <br>$msg_content<br><br> <span class='toggle'><a href='#'>REPLY</a></span> <div class='hiddenDiv'> <input type='hidden' value='$msg_id' name='replyid'> <input type='text' name='replysubject' style='width: 300px;' class='text-box' value='RE: $msg_subject'><br> <textarea name='replycontent' style='width: 298px;' rows='5'></textarea><br><br> <input type='submit' name='replybutton' class='button' value='Reply'> </div> </div> </div>"; echo "<div style='clear: both;'></div>"; echo "</div>"; $num += 1; } } if ($num == 0){ echo "You have no messages in your inbox."; } echo "</form>"; } else echo "You have no messages in your inbox!"; }else echo "You must be logged in to view your messages!"; ?> </div> </td><td width="250"> <?php include("sidebar.inc"); ?> </td> </table> </body> </html> <?php include("footer.inc"); ?> OK, it's the same again!! Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 26, 2010 Author Share Posted November 26, 2010 Please Help this is really annoying me!! Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 27, 2010 Share Posted November 27, 2010 I don't see where you pass the value of the message you want to delete to the deleteorsend.php script. It looks like that script queries the database again without using a WHERE clause to specify the message you're trying to alter. I would start putting some debugging echos in the code in deleteorsend.php to trace just what is happening when the form is submitted. Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 27, 2010 Author Share Posted November 27, 2010 I think I've done that :-\ and it only seems to submit the last reply message no matter which button is pressed. Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 27, 2010 Author Share Posted November 27, 2010 Anyone.... Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 27, 2010 Author Share Posted November 27, 2010 Please!! If I haven't explained myself very well tell me what you need to know! Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 27, 2010 Share Posted November 27, 2010 Stop bumping the thread without adding anything new to it. You say you think you've passed the message id to deleteorsend. Can you point out where that is done? Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 27, 2010 Author Share Posted November 27, 2010 Stop bumping the thread without adding anything new to it. Sorry, I'm very impatient!! I worry that no one will ever reply when obviously they do... You say you think you've passed the message id to deleteorsend. Can you point out where that is done? Yes it's in the first part of the content section: echo "<form action='delete_message.php' method='POST'>"; Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 27, 2010 Share Posted November 27, 2010 That's not a message id, that's the name of the script that is the target of the form being submitted, and the method to use for that submission. You need to pass not only the action to take, but also the primary key id of the message to the second script in order for the second script to select the message it needs to take action on. Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 27, 2010 Author Share Posted November 27, 2010 That's not a message id, that's the name of the script that is the target of the form being submitted, and the method to use for that submission. You need to pass not only the action to take, but also the primary key id of the message to the second script in order for the second script to select the message it needs to take action on. :-\ I think I understand... could you give an example as I am VERY new to php! So do I need to add some sort of id value too? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 27, 2010 Share Posted November 27, 2010 Here's a quick (not all-inclusive) example using no form, and the GET method. If you look at how this works, it should help you understand the logic necessary to manipulate records like you're trying to do. Do as I've indicated below, change the database details to your own in the scripts, then call the list.php file into your browser, and see how it works. -------------------------------------------------- Create a practice table named people by pasting this into the SQL tab in phpMyAdmin CREATE TABLE IF NOT EXISTS `people` ( `pk_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(32) COLLATE utf8_unicode_ci NOT NULL, `rank` varchar(32) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`pk_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=10 ; -- -- Dumping data for table `people` -- INSERT INTO `people` VALUES(1, 'Bob', 'Private'); INSERT INTO `people` VALUES(2, 'Steve', 'Corporal'); INSERT INTO `people` VALUES(3, 'Joe', 'Sergaent'); INSERT INTO `people` VALUES(4, 'Betty', 'Lieutenant'); INSERT INTO `people` VALUES(5, 'Tina', 'Major'); INSERT INTO `people` VALUES(6, 'Victoria', 'Principal'); INSERT INTO `people` VALUES(7, 'Larry', 'Captain'); INSERT INTO `people` VALUES(8, 'Frank', 'Major'); INSERT INTO `people` VALUES(9, 'Sherman', 'Colonel'); Save this as list.php: <?php $host = 'your_db_hostname'; $user = 'your_db_username'; $pass = 'yourdb_password'; $dbname = 'your_db_name'; mysql_connect($host, $user, $pass); mysql_select_db($dbname); $query = "SELECT `pk_id`, `name`, `rank` FROM `people`"; if( $result = mysql_query($query) ) { while( $array = mysql_fetch_assoc($result) ) { echo "{$array['name']} - {$array['rank']} <a href=\"process.php?do=delete&pkid={$array['pk_id']}\">Delete Record</a><br>"; } } ?> And save this as process.php <?php $host = 'your_db_hostname'; $user = 'your_db_username'; $pass = 'yourdb_password'; $dbname = 'your_db_name'; mysql_connect($host, $user, $pass); mysql_select_db($dbname); if( isset($_GET['do']) && $_GET['do'] == 'delete' ) { if( ctype_digit($_GET['pkid']) && intval($_GET['pkid']) > 0 ) { $pk_id = (int) $_GET['pkid']; $query = "DELETE FROM `people` WHERE `pk_id` = $pk_id LIMIT 1"; if( $result = mysql_query($query) ) { echo "<font color=\"red\">" . mysql_affected_rows() . " record was deleted.</font><br><a href=\"" . $_SERVER['HTTP_REFERER'] . "\">[ Delete another ]</a>"; } else { echo "Query failed to execute: " . mysql_error(); } } else { echo "No record specified"; } } else { echo "No action specified."; } ?> Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 27, 2010 Author Share Posted November 27, 2010 I think I already have that here: <input type='hidden' value='$msg_id' name='replyid'> When I echo out "replyid" I don't get a value! Any reason why? Quote Link to comment Share on other sites More sharing options...
jcbones Posted November 27, 2010 Share Posted November 27, 2010 Either change the input type to text. <input type='hidden' value='$msg_id' name='replyid'> <-change to a text input or look at the source code and see if the value is set to the proper Id. At the top of the deleteorsend.php put in some de-bugging code; echo '<pre>'; print_r($_POST); echo '</pre>'; Make sure you have all the values you think you do in the post array. Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 27, 2010 Author Share Posted November 27, 2010 Yes... I have tried printing the code already and I have already said that the content is not displayed. I am trying to make the value hidden as I don't want a random text box popping up!! When I click any reply button the bottom subject and content are sent!!! Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 28, 2010 Author Share Posted November 28, 2010 Sorry, I know you said not to bump but... It's exactly the same as it was before I strated this thread! Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 28, 2010 Share Posted November 28, 2010 Well, did you put the suggested echo '<pre>'; print_r($_POST); echo '</pre>'; at the head of deleteorsend.php and see what it returns? Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 28, 2010 Author Share Posted November 28, 2010 Yes... I have tried printing the code already! Even when I press the message 1 reply button the values are for message 2: Array ( [replyid] => 15 [replysubject] => This is the subject for message 2 [replycontent] => This is the content for message 2 [replybutton] => Reply ) Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 28, 2010 Share Posted November 28, 2010 I think I found it. I can't guarantee this is the only problem in that code, but the hidden field below field will always return the value of its last occurrence in the form because the name= attribute is the same every time. <input type='hidden' value='$msg_id' name='replyid'> In other words, it's the same as setting up a form like this: <form> <input type="text" name="text" value="Text1"> <input type="text" name="text" value="Text2"> <input type="text" name="text" value="Text3"> <input type="text" name="text" value="Text4"> <input type="text" name="text" value="Text5"> <input type="submit" name="submit" value="Submit"> </form> The value in $_POST['text'] will always be "Text5" because its the last instance of it in the form. Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 28, 2010 Author Share Posted November 28, 2010 I think I found it. I can't guarantee this is the only problem in that code, but the hidden field below field will always return the value of its last occurrence in the form because the name= attribute is the same every time. <input type='hidden' value='$msg_id' name='replyid'> In other words, it's the same as setting up a form like this: <form> <input type="text" name="text" value="Text1"> <input type="text" name="text" value="Text2"> <input type="text" name="text" value="Text3"> <input type="text" name="text" value="Text4"> <input type="text" name="text" value="Text5"> <input type="submit" name="submit" value="Submit"> </form> The value in $_POST['text'] will always be "Text5" because its the last instance of it in the form. Ok, that makes sense but how do I fix it? It is in a while loops so do I need to assign some sort of id to it? Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 28, 2010 Author Share Posted November 28, 2010 Ok... I've found a way of making it work but the value for the button is the message id. How can I make it so you don't see "reply16" but just "reply"? Or how can I detect the name of the value? EDIT :: Don't worry! I was being stupid! Of cource I know how to do it with the name! I'm sure I will come into another problem in a few minutes though..... Quote Link to comment Share on other sites More sharing options...
coolcam26 Posted November 28, 2010 Author Share Posted November 28, 2010 Hi, I got it to work at last!! I kind of re-wrote some of the code and finnaly got there in the end! I followed a tutorial so I probably didn't have full understanding of it. Anyway here's my final code incase you were curious: The deleteorsend.php file: <?php include("header.inc"); ?> <table border="0" width="100%"><tr><td valign="top" width="800"> <div id="content"> <?php //Start Content $replybtn = $_POST['replybtn']; $inboxbtn = $_POST['deleteinbox']; $outboxbtn = $_POST['deleteoutbox']; if($_SESSION['uid']){ echo '<pre>'; print_r($_POST); echo '</pre>'; if($inboxbtn){ $query = mysql_query("SELECT * FROM messages WHERE to_user='$username'"); while ($row = mysql_fetch_assoc($query)){ $msg_id = $row['id']; $value = "cb"."$msg_id"; $checkbox = $_POST[$value]; if ($checkbox){ mysql_query("UPDATE messages SET to_delete='1' WHERE id='$msg_id'"); } } echo "The selected messages have been deleted! <a href='messages.php'>Click here</a> to return to your inbox."; } if($outboxbtn){ $query = mysql_query("SELECT * FROM messages WHERE from_user='$username'"); while ($row = mysql_fetch_assoc($query)){ $msg_id = $row['id']; $value = "cb"."$msg_id"; $checkbox = $_POST[$value]; if ($checkbox){ mysql_query("UPDATE messages SET from_delete='1' WHERE id='$msg_id'"); } } echo "The selected messages have been deleted! <a href='messages.php'>Click here</a> to return to your inbox."; } if (!$outboxbtn && !$inboxbtn){ $query = mysql_query("SELECT * FROM messages WHERE to_user='$username'"); while ($row = mysql_fetch_assoc($query)){ $msg_id = $row['id']; $value = "replybtn"."$msg_id"; $replybtn = $_POST[$value]; if ($replybtn){ $subjectname = "replysubject"."$msg_id"; $contentname = "replycontent"."$msg_id"; $subject = $_POST[$subjectname]; $content = $_POST[$contentname]; echo "Content name:".$contentname."<br />"; echo "Subject name:".$subjectname."<br />"; echo "Content:".$content."<br />"; echo "Subject:".$subject."<br />"; if ($subject && $content){ $date = date("M d, Y"); $query = mysql_query("SELECT * FROM messages WHERE content='$content' AND date='$date'"); $numrows = mysql_num_rows($query); if ($numrows == 0){ $query = mysql_query("SELECT * FROM messages WHERE id='$msg_id' AND to_user='$username'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ $row = mysql_fetch_assoc($query); $to_id = $row['from_id']; $to_user = $row['from_user']; mysql_query("INSERT INTO messages (to_user, to_id, from_user, from_id, subject, content, date) VALUES ('$to_user', '$to_id', '$username', '$userid', '$subject', '$content', '$date')"); echo "to user:".$to_user."<br />"; echo "to id:".$to_id."<br />"; echo "from user:".$username."<br />"; echo "from id:".$userid."<br />"; echo "subject:".$subject."<br />"; echo "content:".$content."<br />"; echo "date:".$date."<br />"; echo "Your reply has been sent. <a href='messages.php'>Click here</a> to return to your inbox."; } else echo "No message was sent. An error has occured!!!!"; } else echo "You can NOT resend the same messages."; } else echo "You did not supply a subject and/or message."; } } } } else echo "You must be logged in to do that!"; //End Content ?> </div> </td><td width="250"> <?php include("sidebar.inc"); ?> </td> </table> <?php include("footer.inc"); ?> </div> </div> And the messages(inbox).php file: <head> <script type="text/javascript" src="includes/jquery.js"></script> <script language="javascript" type="text/javascript"> $(document).ready(function(){ //trigger when clicking element $(".toggle").click(function () { //check visibility if ($(this).next().is(":hidden")) { $(this).next().slideDown("slow"); //slide it down } else { $(this).next().hide(); //hide it } }); }); </script> </head> <?php include("header.inc"); ?> <table border="0" width="100%"><tr><td valign="top" width="800"> <?php echo "<div id='content'>"; echo "<h2 div id='title'>"; echo "Messages"; echo "</h2>"; if($_SESSION['uid']){ echo "<div align='right'><a href='create_message.php'>Create Message  </a></div>"; echo "<h3 div id='subtitle'>"; echo "Inbox"; echo "</h3>"; //Inbox/////////////////////////////////////////////////////////////// $query = mysql_query("SELECT * FROM messages WHERE to_user='$username' ORDER BY id DESC"); $numrows = mysql_num_rows($query); if ($numrows > 0){ echo "<form action='deleteorsend.php' method='POST'>"; echo "<div id='messages'> <div id='leftside'>From...</div> <div id='leftside'><input type='submit' name='deleteinbox' value='Delete' class='button'></div> <div id='rightside'>Date</div> <div id='center'>Subject and Message</div> <div style='clear: both;'></div> </div>"; while($row = mysql_fetch_assoc($query)){ $msg_id = $row['id']; $msg_to_user = $row['to_user']; $msg_to_id = $row['to_id']; $msg_from_user = $row['from_user']; $msg_from_id = $row['from_id']; $msg_subject = $row['subject']; $msg_content = $row['content']; $msg_date = $row['date']; $msg_from_delete = $row['from_delete']; $msg_to_delete = $row['to_delete']; if (!$msg_to_delete){ echo "<div id='messages'>"; echo "<div id='leftside'> <input type='checkbox' name='cb$msg_id' value='$msg_id'> <a href='profile.php?id=$msg_from_id' target='_blank'>$msg_from_user</a> </div>"; echo "<div id='rightside'>$msg_date</div>"; echo "<div id='center'> <span class='toggle'><a href='#'>$msg_subject</a></span> <div class='hiddenDiv'> <br>$msg_content<br><br> <span class='toggle'><a href='#'>REPLY</a></span> <div class='hiddenDiv'> <input type='hidden' value='$msg_id' name='reply$msg_id'> <input type='text' name='replysubject$msg_id' style='width: 300px;' class='text-box' value='RE: $msg_subject'><br> <textarea name='replycontent$msg_id' style='width: 298px;' rows='5'></textarea><br><br> <input type='submit' name='replybtn$msg_id' class='button' value='Reply'> </div> </div> </div>"; echo "<div style='clear: both;'></div>"; echo "</div>"; $num += 1; } } if ($num == 0){ echo "You have no messages in your inbox."; } echo "</form>"; } else echo "You have no messages in your inbox!"; }else echo "You must be logged in to view your messages!"; ?> </div> </td><td width="250"> <?php include("sidebar.inc"); ?> </td> </table> </body> </html> <?php include("footer.inc"); ?> Thank you so much for the help!! 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.