0
$select = " SELECT * FROM comments WHERE type=$row->title; ORDER BY id desc" .
         " LIMIT $low, $PerPage";
$final = mysql_query($select) or die('Error!');

$row->title; is previously created and it have value like Type1, Type2 or something else. When I start that script the result is "Error!". Could you tell me why? I have tried many ways to reslove the problem but without any result. This is one of them:

$mytype=$row->title;
$select = " SELECT * FROM comments WHERE type=$mytype; ORDER BY id desc" .
         " LIMIT $low, $PerPage";
$final = mysql_query($select) or die('Error!');

2 Answers 2

3

Remove the ; after the $row-title i.e.:

$select = " SELECT * FROM comments WHERE type='$row->title'  ORDER BY id desc" .          " LIMIT $low, $PerPage"; 
Sign up to request clarification or add additional context in comments.

1 Comment

Added quotes. Thx dqhendricks almost forgot :)
0

You should echo out mysql_error() - MySQL will tell you what went wrong!

The answers by dqhendricks and Cybernate are correct - you should enclose your strings in single quotes.

However - you should also be escaping your text, or you will get more errors eventually:

$select = "SELECT * FROM comments WHERE type='" . mysql_real_escape_string($row->title) . "' ORDER BY id desc LIMIT $low, $PerPage";

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.