jcruze10 Posted June 8, 2013 Share Posted June 8, 2013 Hey guys, hopefully your brilliant minds will be able to enlighten me with a solution to adding a reply link to my current message system and creating a reply page similiar to the compose page. I have yet to build a "reply.php" page so anything you can help me out with would be great. All I'm really needing is for the original sender's member name to echo into the "Send Message To:" field so that the user won't have to retype the sender's name in. Thank you in advance for any assistance you guys can provide. Here's the coding for my "compose.php" & "viewmsg.php" pages: viewmsg.php <?php session_start(); $user = $_SESSION['SESS_LOGIN']; include 'db.php'; //This checks to see if a user is logged in or not by seeing if the sessioned username varialble exists. //You could change this check to however you want to validate your members, this is just how I did it. if(!$user) { echo "<br><p>Please login to view your messages.</p><br>"; } else { //We need to grab the msg_id variable from the URL. $msg_id = $_REQUEST['msg_id']; //Get all of the information about the message with the id number sent through the URL $view_msg = mysql_query("SELECT * FROM messages WHERE id = '$msg_id'"); $msg = mysql_fetch_array($view_msg); $reciever = $msg['reciever']; $sender = $msg['sender']; $subject = $msg['subject']; $message = $msg['message']; //If the person who is supposed to recieve the message is the currently logged in user everything is good if($reciever == $user) { //The message was recieved, so lets update the message in the database so it wont show up in the sent page any more mysql_query("UPDATE messages SET recieved='1' WHERE id = '$msg_id'"); //Query the database to see how many messages the logged in user has, then do a little math //Find the percentage that your inbox is full (message count divided by 50) //50 messages maximum, you can change that $sql = mysql_query ("SELECT pm_count FROM members WHERE login='$user'"); $row = mysql_fetch_array ($sql); $pm_count = $row['pm_count']; //This is the math to figure out the percentage. //The message could divided by 50 then multiplied by 100 so we dont have a number less than 1 $percent = $pm_count/'50'; $percent = $percent * '100'; //Now we will display the little navigation thing, the fullness of the inbox, then display message information stuff, like who its from, the subject, and the body ?> <center> <b><p><a href="inbox.php">Inbox</a> | <a href="compose.php">Compose</a> | <a href="sent.php">Sentbox</a></b> <b><p><?php echo "$pm_count"." of 50 Total | "."$percent"."% full"; ?></p></b> </center> <br> <table width="80%"> <tr> <td width="120px"><p>From:</p></td> <td width=""><p><a href = "<?php echo "../profiles/$sender.php"; ?>"><?php echo $sender; ?></a></p></td> </tr> <tr> <td width="120px"><p>Subject:</p></td> <td width=""><p><?php echo $subject; ?></p></td> </tr> <tr> <td width="120px"><p>Message Body:</p></td> <td width=""><p><?php echo $message; ?></p></td> </tr> </table> </center> <?php } //Everything is not good, someone tried to look at somone else's private message else { ?> <p>Invalid message. Please log out and log back in.</p> <?php } } ?> compose.php <?php session_start(); $user = $_SESSION['SESS_LOGIN']; include 'db.php'; //This checks to see if a user is logged in or not by seeing if the sessioned username varialble exists. //You could change this check to however you want to validate your members, this is just how I did it. if(!$user) { echo "<br><p>Please login to compose a message.</p><br>"; } else { //Query the database to see how many messages the logged in user has, then do a little math //Find the percentage that your inbox is full (message count divided by 50) //50 messages maximum, you can change that $sql = mysql_query ("SELECT pm_count FROM members WHERE login='$user'"); $row = mysql_fetch_array ($sql); $pm_count = $row['pm_count']; //This is the math to figure out the percentage. //The message could divided by 50 then multiplied by 100 so we dont have a number less than 1 $percent = $pm_count/'50'; $percent = $percent * '100'; ?> <center> <b><p><a href="inbox.php">Inbox</a> | <a href="compose.php">Compose</a> | <a href="sent.php">Sentbox</a></b> <b><p><?php echo "$pm_count"." of 50 Total | "."$percent"."% full"; ?></p></b> </center> <br> <?php //So here we get the variable submitted through the form to this page $reciever = $_POST['username']; $subject = $_POST['subject']; $message = $_POST['message']; $error = '0'; //If they are all blank we jsut say to compose a message if(!$reciever AND !$subject AND !$message) { ?> <p><b>Please compose a message.</b></p> <br> <?php } //Since this form was partially filled out we need to return an error message else { if (!$reciever) { $error = 'You must enter a reciever to your message'; } if (!$subject) { $error = 'You must enter a subject'; } if (!$message) { $error = 'You must enter a message'; } //If the variable error is not set to zero, we have a problem and should show the error message if($error != '0') { echo "<p>$error</p><br>"; } //There are no errors so far which means the form is completely filled out else { //Are the trying to send a message to a real user or to something they just made up? $user_check = mysql_query("SELECT login FROM members WHERE login='$reciever'"); $user_check = mysql_num_rows($user_check); //The user is real and not made up if this is true if($user_check > '0') { //There might already be a sessioned time variable, if so we need to get it for the flood check $time = $_SESSION['time']; //If there is a time variable already, set it to the varialbe $old_time if($time > '0') { $old_time = $time; } //Here we get the minutes and seconds on the server time using the date function, and set that to the $time variable //Now we find the difference between this time ($time) and the time that the page was submitted ($old_time) $time = date('is'); $difference = $time - $old_time; $_SESSION['time'] = $time; //If the two times have a difference greater or equal to 15, which is 15 seconds, they can submit the message, this is for flood protection if($difference >= '15') { //Get their private message count $sql = mysql_query ("SELECT pm_count FROM members WHERE login='$reciever'"); $row = mysql_fetch_array ($sql); $pm_count = $row['pm_count']; //You cant have more than 50 private messages, if they try sending a message to a user with a full inbox return an error message if(pm_count == '50') { $error = 'The user you are trying to send a message to has 50 private messages, sorry but we cant send your message until that user deletes some of their messages.'; } else { //And now we stick the message in the database with all the correct information mysql_query("INSERT INTO messages (reciever, sender, subject, message) VALUES('$reciever', '$user', '$subject', '$message')") or die (mysql_error()); //Add 1 to the pm count, update the reciever with the new pm count $pm_count++; mysql_query("UPDATE members SET pm_count='$pm_count' WHERE login='$reciever'"); } //Let the user know everything went ok. echo "<p><b>You have successfully sent a private message!</b></p><br>"; } //Since they are trying to send messages faster than every 15 seconds, give them an error message else { $error = 'You must wait 15 seconds before sending another private message'; } } //If they mis spelled or, made up a username, then give an error message telling them its wrong. else { $error = 'That username does not exist, please try again. Remember to check your spelling.'; } } } //Since we may have set the error variable to something while trying to send the messae, we need another error check if($error != '0') { echo "<p>$error</p><br>"; } else { //Here's the form for the input ?> <form name="send" method="post" action="compose.php"> <table width="80%"> <tr> <td width="150px" align="left" valign="top"><p>Send Message To:</p></td> <td width="" align="left" valign="top"><input name="username" type="text" id="username" value="<?php echo "$reciever"; ?>"></td> </tr> <tr> <td width="150px" align="left" valign="top"><p>Message Subject:</p></td> <td width="" align="left" valign="top"><input name="subject" type="text" id="subject" value="<?php echo "$subject"; ?>"></td> </tr> <tr> <td width="150px" align="left" valign="top"><p>Message Body:</p></td> <td width="" align="left" valign="top"><textarea name="message" type="text" id="message" value="" cols="50" rows="10"></textarea></td> </tr> <tr> <td></td> <td><input type="submit" name="Submit" value="Send Message"></td> </tr> </table> </center> </form> <?php } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/278917-adding-a-reply-link-reply-page-to-my-message-system/ Share on other sites More sharing options...
davidannis Posted June 8, 2013 Share Posted June 8, 2013 I'd just make a link back to compose.php?replyto=$sender and then use the $_GET['replyto'] to address the message. Try it and we'll help with bugs. Quote Link to comment https://forums.phpfreaks.com/topic/278917-adding-a-reply-link-reply-page-to-my-message-system/#findComment-1434790 Share on other sites More sharing options...
jcruze10 Posted June 8, 2013 Author Share Posted June 8, 2013 (edited) Cool, sounds good. Trying to tweak it now. Ehhh, what would the coding look like? <a href="compose.php?replyto=$sender">Reply to this message</a> And where would i place the $_GET['replyto'] at? Edited June 8, 2013 by jcruze10 Quote Link to comment https://forums.phpfreaks.com/topic/278917-adding-a-reply-link-reply-page-to-my-message-system/#findComment-1434806 Share on other sites More sharing options...
jcruze10 Posted June 8, 2013 Author Share Posted June 8, 2013 I'm not a professional coder by any means so I suppose I need to ask if I should set up a new variable in compose.php ? I must be missing something... I added the $_GET['replyto'] here: <tr> <td width="150px" align="left" valign="top"><p>Send Message To:</p></td> <td width="" align="left" valign="top"><input name="username" type="text" id="username" value="<?php echo $_GET['replyto'];?>"></td> </tr> When the reply link is clicked it places "$sender" in the field and not the actual value of the member's username... Quote Link to comment https://forums.phpfreaks.com/topic/278917-adding-a-reply-link-reply-page-to-my-message-system/#findComment-1434807 Share on other sites More sharing options...
davidannis Posted June 8, 2013 Share Posted June 8, 2013 The link should look like this (in context in viewmsg.php <b><p><a href="inbox.php">Inbox</a> | <a href="compose.php">Compose</a> |<a href="compose.php?replyto=<?php echo $sender?>">Reply to this message</a> | <a href="sent.php">Sentbox</a></b> <b><p><?php echo "$pm_count"." of 50 Total | "."$percent"."% full"; ?></p></b> Then in compose try something like: else { if ($_GET['replyto']!='') $receiver=$_GET['replyto']; //Here's the form for the input ?> Quote Link to comment https://forums.phpfreaks.com/topic/278917-adding-a-reply-link-reply-page-to-my-message-system/#findComment-1434834 Share on other sites More sharing options...
jcruze10 Posted June 8, 2013 Author Share Posted June 8, 2013 Awesome Freak Dr. One final touch-up, where in compose.php would I place else { if ($_GET['replyto']!='') $receiver=$_GET['replyto']; //Here's the form for the input ?> Can't seem to find the magic spot. Quote Link to comment https://forums.phpfreaks.com/topic/278917-adding-a-reply-link-reply-page-to-my-message-system/#findComment-1434846 Share on other sites More sharing options...
jcruze10 Posted June 8, 2013 Author Share Posted June 8, 2013 Okay....nevermind, I see what you were saying there. The $_GET command never worked for me, but what I was able to do was: - Created a compose2.php page which was simply a duplicate of compose.php. - Changed the reply link to: <a href="compose2.php?replyto=<?php echo $sender?>"> ------- as you suggested And then finally changed the value of the sender form to: <input name="username" type="text" id="username" value="<?php echo $_GET['replyto'];?>"> So now it officially works and I didn't have to alter the original compose.php page! I probably just wasn't placing your $_GET code in the correct spot, but this seems to be working efficiently. I greatly appreciate your help, you certainly led me to a quick fix. Thank you so much Freak Dr. Quote Link to comment https://forums.phpfreaks.com/topic/278917-adding-a-reply-link-reply-page-to-my-message-system/#findComment-1434857 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.