This question already has answers here:
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource
(31 answers)
Closed 1 year ago.
I'm building a search within my site.
I have a problem with the DB. It's giving me this:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Program Files (x86)\EasyPHP-5.3.5.0\www\searchscript\search.php on line 86
I'll show you the code section where it gives me such error
line 82: $query = "SELECT * FROM dreams WHERE titolo,titch LIKE \"%$trimmed%\" ORDER BY id_dreams DESC ";
line 85: $numresults=mysql_query($query);
line 86: $numrows=mysql_num_rows($numresults); //error
Now I tried to see what is the problem behind the query and it's telling me this:
SELECT * FROM dreams WHERE titolo, titch LIKE "%tags%" ORDER BY id_dreams DESC
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 'titch LIKE "%tags%" ORDER BY id_dreams DESC' at line 1
The code behind this is:
$query = "SELECT * FROM dreams WHERE titolo, titch LIKE \"%$trimmed%\" ORDER BY id_dreams DESC ";
$result = mysql_query($query) or die($query."<br/><br/>".mysql_error());
The mysql_query is returning a boolean value meaning the sql query is probably failing and you're getting a false returned rather than a mysql resource.
Have you checked your query?
You forgot to check whether $num_results is a MySQL result resource. In this case your query errored, so it's FALSE instead.
Re-read the documentation for mysql_query and ensure you program for all possible cases.
Related
This question already has answers here:
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource
(31 answers)
Closed 8 years ago.
I don't understand why I am getting this error:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL
result resource
My code is:
$alreadyMember = mysql_fetch_assoc(mysql_query("SELECT id FROM members WHERE emailAddress='{$_SESSION['register']['email']}'"));
I am also getting the error here:
$alreadyRegistered = mysql_fetch_assoc(mysql_query("SELECT confirm_code FROM memberstemp WHERE emailAddress='{$_SESSION['register']['email']}'"));
If mysql_query() fails, it returns FALSE instead of a MySQL result resource.
So basically mysql_query() is failing and you are passing FALSE to mysql_fetch_assoc() instead of the resource you are supposed to.
You have to run mysql_query() separately and check if it returns FALSE before proceeding, in which case you print mysql_error() to learn what went wrong.
It is best to separate query and the fetching of result for easier debugging and prevent unnecessary error, like:
$query = "SELECT id FROM members WHERE emailAddress='{$_SESSION['register']['email']}'";
$result = mysql_query($query) or die("Error : ".mysql_error.__LINE__);
if ($result) // Test if result has no error
{
$alreadyMember = mysql_fetch_assoc($result);
}
However, it is highly recommended to use prepared statements using PDO to prevent sql injection instead of simple mysql() extensions.
This question already has answers here:
MySQL & PHP Parameter 1 as Resource
(3 answers)
Closed 9 years ago.
I'm trying to do this:
<?php
$query ="SELECT * FROM servers, bans WHERE servers.ServerID = bans.ServerID ORDER BY BanID DESC";
$result = mysql_query($query);
while($row=mysql_fetch_assoc($result)){
?>
but I get this error:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Access\repository\HT2\WH\www.voltzgaming.com\public_html\GBans\index.php on line 139
Your mysql_query($query) is returning a false because you have a syntax error in the SQL.
Use mysql_error() after the query is run to see what the problem is.
Plz Help i Dont know what is wrong in this function ....
$gsql = "SELECT * FROM posts WHERE group='$group_name' ORDER BY postdate DESC LIMIT 0,20";
$gquery = mysqli_query($db_conx, $gsql);
$gstatusnumrows = mysqli_num_rows($gquery);
while ($grow = mysqli_fetch_array($gquery, MYSQLI_ASSOC)) {
and it keeps saying this error :-
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in D:\group.php on line 3
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in D:\group.php on line 5
That means your query failed.
[mysqli_query] returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.
So use mysqli_error to find out what you did wrong. In this case, though, it's because you have a column named "group". GROUP is a reserved word in MySQL. To be on the safe side, ALL database, table and column names SHOULD be enclosed in backticks ` to prevent any possible ambiguity.
This question already has answers here:
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource
(31 answers)
Closed 2 years ago.
I'm building a search within my site.
I have a problem with the DB. It's giving me this:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Program Files (x86)\EasyPHP-5.3.5.0\www\searchscript\search.php on line 86
I'll show you the code section where it gives me such error
line 82: $query = "SELECT * FROM dreams WHERE titolo,titch LIKE \"%$trimmed%\" ORDER BY id_dreams DESC ";
line 85: $numresults=mysql_query($query);
line 86: $numrows=mysql_num_rows($numresults); //error
Now I tried to see what is the problem behind the query and it's telling me this:
SELECT * FROM dreams WHERE titolo, titch LIKE "%tags%" ORDER BY id_dreams DESC
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 'titch LIKE "%tags%" ORDER BY id_dreams DESC' at line 1
The code behind this is:
$query = "SELECT * FROM dreams WHERE titolo, titch LIKE \"%$trimmed%\" ORDER BY id_dreams DESC ";
$result = mysql_query($query) or die($query."<br/><br/>".mysql_error());
The mysql_query is returning a boolean value meaning the sql query is probably failing and you're getting a false returned rather than a mysql resource.
Have you checked your query?
You forgot to check whether $num_results is a MySQL result resource. In this case your query errored, so it's FALSE instead.
Re-read the documentation for mysql_query and ensure you program for all possible cases.
This question already has answers here:
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource
(31 answers)
Closed 8 months ago.
I get following Error:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in......
Here is my Query:
$query = "SELECT ListNumber FROM residential";
$result1 = mysql_query($query);
if (mysql_num_rows($result1) >10){
$difference = mysql_num_rows($result1) - 10;
$myQuery = "SELECT * FROM `residential` ORDER BY `id` LIMIT 10,". $difference;
$result2 = mysql_query($myQuery);
while ($line = mysql_fetch_array($result2, MYSQL_BOTH))
Your query ($myQuery) is failing and therefore not producing a query resource, but instead producing FALSE.
To reveal what your dynamically generated query looks like and reveal the errors, try this:
$result2 = mysql_query($myQuery) or die($myQuery."<br/><br/>".mysql_error());
The error message will guide you to the solution, which from your comment below is related to using ORDER BY on a field that doesn't exist in the table you're SELECTing from.
The code you have posted doesn't include a call to mysql_fetch_array(). However, what is most likely going wrong is that you are issuing a query that returns an error message, in which case the return value from the query function is false, and attempting to call mysql_fetch_array() on it doesn't work (because boolean false is not a mysql result object).
mysql_fetch_array() expects parameter 1 to be resource boolean given in php error on server if you get this error : please select all privileges on your server. u will get the answer..
This error comes when there is error in your query syntax check field names table name, mean check your query syntax.