supermerc Posted December 19, 2006 Share Posted December 19, 2006 Hey i followed the tutorial on how to make the private messaging system. When it send a message you can only send the message to a user from a drop down list, but i want my users to be able to enter the username into a field instead but i dont know how.this is my code[code]<?php// Process the message once it has been sentif (isset($_POST['newMessage'])) { // Escape and prepare our variables for insertion into the database // This is also where you would run any sort of editing, such as BBCode parsing $to = mysql_real_escape_string($_POST['to']); $from = $_SESSION['userID']; $sub = mysql_real_escape_string($_POST['subject']); $msg = mysql_real_escape_string($_POST['message']); // Handle all your specific error checking here if (empty($to) || empty($sub) || empty($msg)) { $error = "<p>You must select a recipient and provide a subject and message.</p>\n"; } else { // Notice carefully how we only have to provide the five values we previously discussed $sql = "INSERT INTO myPMs (to_id, from_id, time_sent, subject, message) VALUES ('$to', '$from', NOW(), '$sub', '$msg')"; if (!mysql_query($sql)) { $error = "<p>Could not send message!</p>\n"; } else { $message = "<p>Message sent successfully!</p>\n"; } }}echo isset($error) ? $error : '';echo isset($message) ? $message : '';echo "<form name=\"newMessage\" action=\"\" method=\"post\">\n";echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";echo "<tr>\n";echo "<td>To:</td>\n";echo "<td><select name=\"to\">\n";echo "<option value=\"\"></option>\n";// Collect and loop through all usernames that are not the current user$sql = mysql_query("SELECT * FROM users WHERE id != '$_SESSION[userid]' ORDER BY username");if (mysql_num_rows($sql) > 0) { while ($x = mysql_fetch_assoc($sql)) echo "<option value=\"$x[id]\">$x[username]</option>\n";}echo "</select></td>\n";echo "</tr>\n";echo "<tr>\n";echo "<td>Subject:</td>\n";echo "<td><input type=\"text\" name=\"subject\" value=\"" . (isset($error) ? $_POST['subject'] : '') . "\" maxlength=\"50\" /></td>\n";echo "</tr>\n";echo "<tr>\n";echo "<td>Message:</td>\n";echo "<td>\n";echo "<textarea name=\"message\" cols=\"\" rows=\"\">" . (isset($error) ? $_POST['message'] : '') . "</textarea>\n";echo "</td>\n";echo "</tr>\n";echo "<tr>\n";echo "<td></td>\n";echo "<td><input type=\"submit\" name=\"newMessage\" value=\"Send\" /></td>\n";echo "</tr>\n";echo "</table>\n";echo "</form>\n";?> [/code]Please help me Link to comment https://forums.phpfreaks.com/topic/31277-solved-private-messaging-system-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.