Parse error trying to display MySQL DB data
Posted: Sun Sep 14, 2003 5:03 pm
I am new to PHP. Can someone tell me what is wrong with this code? It does everything it is supposed to do, except that when it loads without passed variables, I get the following error message:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/eautospot/www/reviews2.php on line 67
The page is at http://www.eautospot.com/reviews2.php. Here is the code:
Any help would be appreciated. Thanks.
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/eautospot/www/reviews2.php on line 67
The page is at http://www.eautospot.com/reviews2.php. Here is the code:
Code: Select all
<html>
<head>
<title> Review Lister TEST </title>
</head>
<body>
<?php
if (isset($_GETї"addreview"])): // If the user wants to add a record
?>
<form action="<?=$_SERVERї"PHP_SELF"]?>" method="post">
<p>Enter your first name:<br />
<input type=text name="FirstName" />
<p>Enter your last name:<br />
<input type=text name="LastName" />
<p>Enter your email:<br />
<input type=text name="Email" />
<p>Give your review a title:<br />
<input type=text name="Title" />
<p>Enter your review (HTML ok):<br />
<textarea name="Review" rows="10" cols="40" wrap></textarea><br />
<input type="submit" name="submitreview" value="SUBMIT" /></p>
</form>
<?php
else:
// Connect to the database server
$dbcnx = @mysql_connect("localhost", "XXXXXXXX", "********");
if (!$dbcnx) {
echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
exit();
}
// Select the database
if (! @mysql_select_db("XXXXXXXX") ) {
echo( "<p>Sorry, but I was not able to get into your " .
"database at this time.</p>" );
exit();
}
// If a post has been made, add it
if (isset($_POSTї"submitreview"])) {
$firstname = $_POSTї"FirstName"];
$lastname = $_POSTї"LastName"];
$email = $_POSTї"Email"];
$title = $_POSTї"Title"];
$review = $_POSTї"Review"];
$sql = "INSERT INTO eautospot_reviews SET
FirstName='$firstname',
LastName='$lastname',
Email='$email',
Title='$title',
Review='$review'";
if (@mysql_query($sql)) {
echo ("<p>Your review has been posted.</p>");
} else {
echo ("<p>Sorry, your review was not posted because of the following: " . mysql_error() . "</p>");
}
}
//If a user elects to view a review
if (isset($_GETї"readreview"])) {
$readid = $_GETї"readreview"];
$result = @mysql_query("SELECT ID, Email, Title, Review FROM eautospot_reviews WHERE ID=$readid");
}
//Show an individual review
//THE NEXT LINE IS WHERE THE ERROR COMES IN
while ($row = mysql_fetch_array($result)) {
$readidtext = $rowї"ID"];
$emailtext = $rowї"Email"];
$titletext = $rowї"Title"];
$reviewtext = $rowї"Review"];
echo ("<B>$titletext</B><BR>$reviewtext<P><A HREF="mailto:$emailtext">Email the reviewer</A></P>");
}
echo("<p> Here is a list of all of our reviews: </p>");
// Request the ID and titles of all reviews
$result = @mysql_query("SELECT ID, Title FROM eautospot_reviews");
if (!$result) {
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
// Display the title of each review with alink to the review
while ( $row = mysql_fetch_array($result) ) {
$reviewid = $rowї"ID"];
$reviewtitle = $rowї"Title"];
echo("<B><a href='$PHP_SELF?readreview=$reviewid'>$reviewtitle</a></p>");
}
// When clicked, this link will load this page with a submit form
echo("<p><a href='$PHP_SELF?addreview=1'>Add your own review!</a></p>");
endif;
?>
</blockquote>
</body>
</html>