Jump to content
Larry Ullman's Book Forums

spsteve

Members
  • Posts

    4
  • Joined

  • Last visited

spsteve's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Excellent! That did it. I didn't realize that the issue was that I needed to apply nl2br() to the displaying of the post, but not the entering of the post. So, I just did echo nl2br("<p>{$messages['username']} ({$messages['posted']})<br />{$messages['message']}</p><br />\n"); And it worked perfect.
  2. Sorry about that. i'm new to this. I think this is the code that is doing the actual posting, but I could be wrong again. I'm working through Larry's book and trying to understand it all, so i appreciate your patience. <?php # Script 17.6 - post_form.php // This page shows the form for posting messages. // It's included by other pages, never called directly. // Only display this form if the user is logged in: if (isset($_SESSION['user_id'])) { // Display the form: echo '<form action="post.php" method="post" accept-charset="utf-8">'; // If on read.php... if (isset($tid) && $tid) { // Print a caption: echo '<h3> Post a Reply</h3>'; // Add the thread ID as a hidden input: echo '<input name="tid" type="hidden" value="' . $tid . '" />'; } else { // New thread // Print a caption: echo '<h3>New Story</h3>'; // Create subject input: echo '<p><em>Subject</em>: <input name="subject" type="text" size="60" maxlength="100" '; // Check for existing value: if (isset($subject)) { echo "value=\"$subject\" "; } echo '/></p>'; } // End of $tid IF. // Create the body textarea: echo '<p><em>Body</em>: <textarea name="body" rows="28" cols="128">'; if (isset($body)) { echo $body; } echo '</textarea></p>'; // Finish the form: echo '<input name="submit" type="submit" value="Submit" /> </form>'; } else { echo '<p>You must be logged in to post messages.</p>'; } ?>
  3. Thanks for your help on this! I've read a little about the nl2br() function and the str_replace, but where would I put it in my code? Here's my code (straight from the book), but I don't see where I could put the nl2br() or str_replace functions. Any help is greatly appreciated: // Validate thread ID ($tid), which may not be present: if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['tid']) && filter_var ($_POST['tid'], FILTER_VALIDATE_INT, array ('min_range' => 1)) ) { $tid = $_POST['tid']; } else { $tid = FALSE; } //If there's no thread ID, a subject must be provided: if (!$tid && empty($_POST['subject'])) { $subject = FALSE; echo '<p>Please enter a subject for this post.</p>'; } elseif (!$tid && !empty($_POST['subject'])) { $subject = htmlspecialchars(strip_tags($_POST['subject'])); } else { $subject = TRUE; } if (!empty($_POST['body'])) { $body = htmlentities($_POST['body']); } else { $body = FALSE; echo '<p>Please enter some text for this post.</p>'; } if ($subject && $body) { // Add the message to the database... if (!$tid) { // Create a new thread. $q = "INSERT INTO threads (user_id, subject) VALUES ({$_SESSION['user_id']}, '" . mysqli_real_escape_string($dbc, $subject) . "')"; $r = mysqli_query($dbc, $q); if (mysqli_affected_rows($dbc) == 1) { $tid = mysqli_insert_id($dbc); } else { echo '<p>Your post could not be handled due to a system error.</p>'; } } if ($tid) { $q = "INSERT INTO posts (thread_id, user_id, message, posted_on) VALUES ($tid, {$_SESSION['user_id']}, '" . mysqli_real_escape_string($dbc, $body) . "', UTC_TIMESTAMP())"; $r = mysqli_query($dbc, $q); if (mysqli_affected_rows($dbc) == 1) { echo '<p>Your post has been entered.</p>'; } else { echo '<p>Your post could not be handled due to a system error.</p>'; } }
  4. In chapter 17, when creating the post.php file, for some reason it does not register the enter/return key as starting a new paragraph, so it displays as one big paragraph for each post. What am I doing wrong?
×
×
  • Create New...