Click to See Complete Forum and Search --> : Querying a databse using MySql


griffen
06-05-2001, 12:40 PM
I have a php script below, but it keeps coming up with a parse error. Is that a problem with MySql or is it an error in the script?

When I get rid of the lower section of the PHP, it comes up with an error saying "Probelm connecting to the database"

Any ideas would be much appreciated.

James.

<HTML>
<HEAD><TITLE> Our List of Jokes

</TITLE>

<HEAD>

<BODY>

<?php // Connect to the database server

$dbcnx = @mysql_connect("localhost", "root", "******");

if (!$dbcnx) {

echo( "<P>Unable to connect to the " . "database server at this time.</P>" );

exit(); }

// Select the jokes database

if (! @mysql_select_db("jokes") ) {

echo( "<P>Unable to locate the joke " . "database at this time.</P>" );

exit();

}

?>

<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 Jokes");

if (!$result) {

echo("<P>Error performing query: " .

mysql_error() . "</P>");
exit();

}

// Display the text of each joke in a paragraph

while ( $row = mysql_fetch_array($result) )

{

echo("<P>" . $row["JokeText"] . "</P>");

}

?>
</BLOCKQUOTE>
</BODY>
</HTML>

r00t619
06-05-2001, 05:17 PM
griffen,

By default the root login to mysql db is NULL aka blank. It is NOT your root passwd for the box. If you want to change your passwd which is recommended you need to look into the mysqladmin binary or login into the mysql db and use the GRANT option.