Hi I'm a bit of a noob with PHP and SQL. I've bought Kevin Yank's "Build your own database driven website using PHP & MYSQL" and I seem to have hit a brick wall.
I'm running apache and mysql on my computer. With running simple php files on the local host I've had no problems. However when I try to connect to my database in chapter 4 (the bit that displays jokes in the database) none of the PHP code seems to work.
At first I presumed I must have some typos, so I downloaded the archive for the book and used that file. I've changed the appropriate settings in this file (the password) yet I still get nothing.
The thing is, it's supposed to display an error message if it doesn't connect, I just get a blank page and nothing (php OR HTML) runs AFTER the first bit of PHP. I don't even get the error messages.
This is my code:
NOTE: 'password' is the passwordCode:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Our List of Jokes</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php // Connect to the database server $dbcnx = @mysql_connect('localhost', 'root', 'password'); if (!$dbcnx) { exit('<p>Unable to connect to the ' . 'database server at this time.</p>'); } // Select the jokes database if (!@mysql_select_db('ijdb')) { exit('<p>Unable to locate the joke ' . 'database at this time.</p>'); } ?> <p>Here are all the jokes in our database:</p> <blockquote> <?php // Request the text of all the jokes $result = @mysql_query('SELECT joketext FROM joke'); if (!$result) { exit('<p>Error performing query: ' . mysql_error() . '</p>'); } // Display the text of each joke in a paragraph while ($row = mysql_fetch_array($result)) { echo '<p>' . $row['joketext'] . '</p>'; } ?> </blockquote> </body> </html>





Bookmarks