0

I'm trying to get a row from the DB using php, i've made an html form that's supposed to take a book title from users and gets the review from the DB about this book, and then post it in an input text, the form's action leads to the following function :

function GetReview($BookTitle)
{
require'DB.php';
if(empty($_POST['BookTitle']))
    {
        echo " You must enter a book name!";
        return false;
    }

$BookTitle = mysql_real_escape_string($BookTitle);

$q="Select Reviews from Users_Booklist where (Book_Title like '%" .$BookTitle."%');";
if(!mysql_query($q,$con))
{
die("Error".mysql_error());
}
else
{
$row = mysql_fetch_row($q);
?>
<html>
<head><title>Delete Review </title>
</head>
<body> 
<br>
<form name="DeleteReview " action="DeleteReviewsFunction.php" method="post">
Review: <input type="text" name="Review" size="200" value="<?php echo $row[0]; ?>"/>            
<input type="submit" value="Delete Review" />
</form>
</body>
</html>
<?php
}
}
GetReview($_POST['BookTitle'])

However, it leads me to the next form with nothing in the input text and this warning:

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in     C:\AppServ\www\GetReview.php on line 20 

I've searched and tried different code but still same result. Could anyone please tell me where the error is???... Thanks

3

3 Answers 3

3
$qq = mysql_query($q,$con);
if(!$qq) {
// (...)

$row = mysql_fetch_row($qq);
Sign up to request clarification or add additional context in comments.

Comments

0

I'm not going to be a lot of help, but your question seems to be where the error is occuring, and I can tell you that.

It's in the $row = mysql_fetch_row($q); line.

You can tell this because the error record starts with mysql_fetch_row(), and the above line is the only mention of mysql_fetch_row() in the code.

Comments

0

Check the SQL query by printing the output of $q variable with:

echo $q;

Now, try to execute it from your MySQL client. Collect the results (if there are) and check for errors.

A suggestion: If you want, you can use a tool like ezSQL that can be very useful (especially for code organization)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.