0

I am getting following error when trying to click the next or previous button on following site:
http://bdworld.co/newest.php?categoryId=35

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/content/69/9332569/html/imagewar/newest.php on line 30
Newest Pictures! ( Others )

SQL query failed. Check your query.

Error Returned: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY m_date DESC' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY m_date DESC' at line 1

The code in line 28-32 is:

<?php
                $result = mysql_query("SELECT cat.Name, sub.Name FROM sub_categories sub, categories cat WHERE cat.Id = sub.CategoryId AND sub.id=$categoryId;");
                while($row = mysql_fetch_array($result)){
                    $categoryName=$row["0"];
                    $subCategoryName=$row["1"];

Can anyone tell me what is the problem

7
Contributors
13
Replies
35
Views
4 Years
Discussion Span
Last Post by simplypixie
0

Should this:

$result = mysql_query("SELECT cat.Name, sub.Name FROM sub_categories sub, categories cat WHERE cat.Id = sub.CategoryId AND sub.id=$categoryId;");

Be:

$result = mysql_query("SELECT cat.Name, sub.Name FROM sub_categories sub, categories cat WHERE cat.Id = sub.CategoryId AND sub.id=$categoryId");

?

0

I changed it but not working. Still the same error

Edited by robin.aditta1

0

What error do you get when you put:

$result = mysql_query("SELECT cat.Name, sub.Name FROM sub_categories sub, categories cat WHERE cat.Id = sub.CategoryId AND sub.id=$categoryId") or die($myQuery."<br/><br/>".mysql_error());

??

0

When I put the above code I get this error:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/content/69/9332569/html/imagewar/winningest.php on line 29
Winningest Pictures! ( Others )

SQL query failed. Check your query.

Error Returned: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY percent DESC' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY percent DESC' at line 1

0

I have replace your code for Newest Pictures, Winningest Pictures and Losingest Pictures and now I am getting only this error:

you have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Edited by robin.aditta1

0

try this
$result = mysql_query("SELECT cat.Name, sub.Name FROM sub_categories AS sub, categories AS cat WHERE cat.id=sub.categoryId AND sub.id=$categoryId

0

If that doesn't work, maybe try:

SELECT cat.Name, sub.Name FROM sub_categories AS sub LEFT JOIN categories AS cat ON cat.id=sub.categoryId WHERE sub.id=$categoryId

0

Get yourself a clearer error dump... try using trigger_error or mysql_error. More info can be found in the official PHP manual.

I would also plead that you use MySQLi or PDO rather than MySQL and look into prepared statements. It makes database driven web applications so much easier to create and maintain whilst also protecting you from SQL Injection attacks.

Either way, try to get a better error report as guided above or carry on as you will and good luck!

0

What error do you get when you put:

$result = mysql_query("SELECT cat.Name, sub.Name FROM sub_categories sub, categories cat WHERE cat.Id = sub.CategoryId AND sub.id=$categoryId") or die($myQuery."<br/><br/>".mysql_error());
??

Only just noticed phorces response - it's good advice. As said in my last post, get yourself better errors and programming will become a million times easier :)

0

No offence but you're just looking for answers by copy and pasting suggestions by users. Perhaps you should do as suggested above and dump a more detailed error message; that will allow most the community here to give you a working solution.

0

You are looking at the wrong query - the error message states you have an error near 'ORDER BY m_date DESC' in your original post and then the next error is near 'ORDER BY percent DESC' in a later reply but the query you have posted has no ORDER BY in it at all. So firstly you need to find the correct query that is causing the error as it is not the one you have posted

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.