Jump to content
Larry Ullman's Book Forums

Ch 17: Message Board Issue


Recommended Posts

Hello. I really like your tutorial style, Larry, and have found you tutorials to be clear and straightforward. That said, I have the message board working fine on my local XAMPP host, however when I tested the message board on a live Web server, its not returning anything at all in 3 areas:

 

1) No "Posted on" date/time

 

2) No "Latest reply" date/time

 

3) Nothing is returned when the "subject" topic is clicked (normally this would return the post content and a reply box).

 

I should specify that I have not completed the registration/login section yet - I've completed everything up to p.528 so far. Also, the Web server version I tested the message board on is PHP 5.2.6. Thanks much.

Link to comment
Share on other sites

Thanks for your quick reply, Larry! I had a feeling that was the problem. The Web host that the message board is currently on (for testing) seems to be sub-par. Do I, necessarily, need to see a "mysql" database in my Web hosts phpMyAdmin page - with the "information_schema" database, etc? Right now only my domain database, the "information_schema" database and "test" database are included. Should I be able to simply request to the server admin that the MySQL timezones be installed? Lastly, would this issue also explain why nothing is returned when I click the subject line in the forum? Thank you.

Link to comment
Share on other sites

Well, I wrote the web server admin, requesting that he install MySQL timezones, and this is what he responded: "The server has the correct time zone running, I just set the "Global" time zone for mysql to be the system time. Let me know if that is what you need."

 

The message board is still not functioning, and I'm not sure how to further clarify to him what I might need done on the server? Thanks again, Larry.

Link to comment
Share on other sites

THe admin needs to install the full list of MySQL timezones IN MySQL so that you can use time zone conversions. You could provide the admin with a link to the MySQL page (regarding installation of the time zones) to make it more clear.

Link to comment
Share on other sites

Ok, sir - time issue is now resolved. Next I just need to figure out why the heck the threads/post reply page is not displaying when I click on a post "Subject". I'm going to be doing some debugging. If you have any ideas, that would be great. If not I understand, as it could be quite a few things I imagine. Thanks again for all of your help today.

Link to comment
Share on other sites

Well I've been trying to debug the issue of the "subject" link on the forum.php page not displaying when clicked, for quite a few hours now. The read.php page displays normally upon clicking a subject heading on the forum.php page, except the body content of the read.php page is completely empty - no text and no error prompt either. Again, the message board works fine on my local XAMPP host - its only an issue when on a live Web server. I went through every table and field in both MySQL databases (XAMPP and Web host) and all the related php files. Any ideas to head me in the right direction, Larry?

 

BTW, does it matter that I'm using one database with unrelated (to the message board tables) tables in it? Not sure if its recommended practice to create a brand-new database for such things?

 

Thanks much.

Link to comment
Share on other sites

Here's what was reported, Larry:

 

"Fatal error: Call to undefined function filter_var() on line 11"

 

And the related function...

 

9. // Check for a thread ID:

10. $tid = FALSE;

11. if (isset($_GET['tid']) && filter_var($_GET['tid'], FILTER_VALIDATE_INT, array('min_range' => 1)) ) {

Link to comment
Share on other sites

Ok - thanks. I will research that. Btw, would it be out of the ordinary to ask the Web server company to update their PHP version? The server service has been sub par, and the system seems outdated to me. Current version stats:

 

PHP Version 5.2.6

 

FreeBSD 6.4-RELEASE-p8 FreeBSD 6.4-RELEASE-p8 #1 r101746: Mon Aug 30 10:34:40 MDT 2010 root@..usr/src/sys/i386/compile/VKERN i386

 

Build Date:May 7 2008 22:22:24

Link to comment
Share on other sites

Ok - I have the message board working on the live server now, after removing Filter Extension and using the simple GET method:

 

 

// Check for a thread ID:

$tid = FALSE;

if (isset($_GET['tid'])) {

 

Do you see any problems with this method used in this context, even though it works - I mean technically, Larry? Thanks again for your guidance and help - sincerely much appreciated.

Link to comment
Share on other sites

  • 4 months later...

hey sir i just got a little problem here, when im trying to post the message, although it runs smoothly, it prompts " Your post could not be handled due to a system error.". that happens when i am creating a new thread, it seems like the queries dont work? any idea about that sir? and also for the remedy?

Link to comment
Share on other sites

I finished the message board example it all worked on my localhost. Which script are you encountering the problem on, can you print us out the php error you are receiving?

 

 

<?php # Script 17.7 - post.php

// This page handles the message post.

// It also displays the form if creating a new thread.

include ('includes/header.html');

 

if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form.

 

// Language ID is in the session.

// Validate thread ID ($tid), which may not be present:

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 { // Thread ID, no need for subject.

$subject = TRUE;

}

 

// Validate the body:

if (!empty($_POST['body'])) {

$body = htmlentities($_POST['body']);

} else {

$body = FALSE;

echo '<p>Please enter a body for this post.</p>';

}

 

if ($subject && $body) { // OK!

 

// Add the message to the database...

 

if (!$tid) { // Create a new thread.

$q = "INSERT INTO threads (lang_id, user_id, subject) VALUES ({$_SESSION['lid']}, {$_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>'; "this is the result when i tried to submit it what might be the problem?"

}

} // No $tid.

 

if ($tid) { // Add this to the replies table:

$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>';

}

} // Valid $tid.

 

} else { // Include the form:

include ('includes/post_form.php');

}

 

} else { // Display the form:

 

include ('includes/post_form.php');

 

}

 

include ('includes/footer.html');

?>

Link to comment
Share on other sites

So what happens when you reply to a current thread? Do you still get an error?

 

I tried my post.php in response to a thread and to post a new thread and both were working. Did you setup the database and fill it in with the sample data that was provided in the sql file download for chap 17?

Link to comment
Share on other sites

So what happens when you reply to a current thread? Do you still get an error?

 

I tried my post.php in response to a thread and to post a new thread and both were working. Did you setup the database and fill it in with the sample data that was provided in the sql file download for chap 17?

 

i got it i just mispelled posts to post hooh problem was resolved! but i was still in the error of no showing the dates under "posted on" and "latest reply" what steps should i do to resolve this? i even tried copy paste the timezone ,the one i downloaded in mysql site, in this address "c:\wamp\bin\mysql" what was wrong then?

Link to comment
Share on other sites

 Share

×
×
  • Create New...