doddsey_65 Posted March 26, 2010 Share Posted March 26, 2010 Okay i thought this would be easier than it has been but now i need some help. The users have their own my account section. From here they can compose a new message which takes them to compose.php with a simple form. When they send a message, the contents of the form(sendto, subject, message) get sent to the database. Now they can also click on their inbox which displays all their messages by selecting all messages from the message table with their username in the sendto field. This all works fine and i am happy with it so far. The only problem is how would i do a reply option? meaning when the user clicks reply under the mesage how would i send them to compose.php with the message field already filled out with the message for which they are replying to? Here is the code for inbox.php if it helps. <?php ob_start(); include('header.php'); include('db.php'); $db=mysql_connect($db_host,$db_user,$db_pass) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db($db_name,$db); $url = $_SERVER["REQUEST_URI"]; //checks cookies to make sure they are logged in if (isset ($_COOKIE['ID_my_site'])) { $username = mysql_real_escape_string($_COOKIE['ID_my_site']); $pass = mysql_real_escape_string($_COOKIE['Key_my_site']); $check = mysql_query("SELECT * FROM users WHERE username = '{$username}'")or trigger_error (mysql_error()); if (mysql_num_rows ($check) > 0) { $info = mysql_fetch_array ($check); //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']) { header("Location: login.php"); } //otherwise they are shown the admin area else { $pagenum = $_GET['pagenum']; if (!(isset($pagenum))) { $pagenum = 1; } //Here we count the number of results //Edit $data to be your query $data = mysql_query("SELECT * FROM publicgallery") or die(mysql_error()); $rows = mysql_num_rows($data); //This is the number of results displayed per page $page_rows = 3; //This tells us the page number of our last page $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } //This sets the range to display in our query $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; echo '<br><div id="page"><div id="content"><br>'; echo '<h2 class="title">Inbox</h2><br>'; $result = mysql_query("SELECT * FROM messages WHERE sentto = '$username' $max") or die(mysql_error()); while($row = mysql_fetch_object($result)) { echo '<div class="post"><p class="meta"><font size=2>'; if ($row->read == 0) { echo '<img src=new.png>'; } echo 'Sent From | ' . $row->sentfrom . '</p>'; echo '<div class="entry"><p>'; echo '<a href=inbox.php?message=' . $row->subject . '>' . $row->subject . '</a>'; echo '<hr>'; echo '</p><br><a href=compose.php>Reply</a> | <a href=#>Delete</a></div></div>'; } echo " Page $pagenum of $last <p>"; if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> "; } echo " ---- "; if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } echo '</div>'; } } } else { header("Location: login.php"); exit (0); } include('footer.php'); ?> And here is the code for compose.php: <?php ob_start(); include('header.php'); include('db.php'); $db=mysql_connect($db_host,$db_user,$db_pass) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db($db_name,$db); //checks cookies to make sure they are logged in if (isset ($_COOKIE['ID_my_site'])) { $username = mysql_real_escape_string($_COOKIE['ID_my_site']); $pass = mysql_real_escape_string($_COOKIE['Key_my_site']); $check = mysql_query("SELECT * FROM users WHERE username = '{$username}'")or trigger_error (mysql_error()); if (mysql_num_rows ($check) > 0) { $info = mysql_fetch_array ($check); //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']) { header("Location: login.php"); } //otherwise they are shown the admin area else { $url = $_SERVER["REQUEST_URI"]; if (isset($_POST['send_btn'])) { if (!$_POST['username'] | !$_POST['subject'] | !$_POST['message'] ) { die('You did not complete all of the required fields'); } $insert = "INSERT INTO messages (sentfrom, sentto, subject, contents) VALUES ('".$_POST['username']."', '".$_POST['username']."', '".$_POST['subject']."', '".$_POST['message']."')"; $send_message = mysql_query($insert); ?> <br> <div id="page"> <div id="content"> <div class="post"> <p class="meta">Your message has been sent <img src="images/img08.png" alt="bullet"></p> <div class="entry"> <p><font size=2><a href=myaccount.php>My Account | <a href=compose.php>Send Another message</a></font></p> <?php } else { echo '<br><div id="page"><div id="content"><br>'; echo '<h2 class="title">Inbox</h2><br>'; echo '<div class="post"><p class="meta"><font size=2>'; echo 'Compose New Message</font><img src="images/video.png" alt="bullet"></p>'; echo '<div class="entry"><p>'; ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> To: <input type="text" name="username"> Subject: <input type="text" name="subject"><br><br> Your Message<br> <textarea name="message" rows=10 cols=40></textarea><br> <input type="submit" name=send_btn value=Send> </form> <?php } echo '</p></div></div></div>'; } } } else { header("Location: login.php"); exit (0); } include('footer.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/196579-private-message-system/ Share on other sites More sharing options...
Wolphie Posted March 26, 2010 Share Posted March 26, 2010 Well, hopefully in your database table you store the ID of the person sending the message, and the recipients ID. Just click on their message, get the ID of the recipient from the database and use that as the recipient once again. If you reference the ID of the message you're replying to in the URL, for example reply.php?id=67 You can then continue to pull all of the information from the database for that message ID, and retrieve the subject, the message, the recipient, the sender, etc.. Quote Link to comment https://forums.phpfreaks.com/topic/196579-private-message-system/#findComment-1032148 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.