textbox Posted May 24, 2007 Share Posted May 24, 2007 Hello, <?php // Process the message once it has been sent if (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[username]' ORDER BY username"); if (mysql_num_rows($sql) > 0) { while ($x = mysql_fetch_assoc($sql)) echo "<option value=\"$x[id]\">$x[username]</option>\n"; } How would I have a button on a seperate page that links to this script, but pass the script the TO USER part. Any ideas?! Thanks Nick Quote Link to comment https://forums.phpfreaks.com/topic/52803-send-message-link/ Share on other sites More sharing options...
AJReading Posted May 24, 2007 Share Posted May 24, 2007 USE POST: <form action="myPage.php" method="post"> <input type="hidden" name="to" value="toUserID"> <input type="button" name="myButton" value="Send Message"> </form> This would use a hidden field to pass the toUserID (which you would have to dynamically enter) to the $_POST['to'] variable in your script Or you could use GET and do somthing like: <a href="myPage.php?uid=toUserID">Send Message</a> Quote Link to comment https://forums.phpfreaks.com/topic/52803-send-message-link/#findComment-260691 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.