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.
Related
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 8 years ago.
When I restart my page I received following mistake:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in
on this string:
while($row=mysql_fetch_array($emp_query)){ $id=$row['history_id'];"
What I did wrong in this code? Without following words in my MySQL query:
"WHERE user Like"
my code is work.
My code
<?php
$emp_query=mysql_query("SELECT * FROM `history` WHERE user LIKE $login_session");
while($row=mysql_fetch_array($emp_query)){ $id=$row['history_id'];
?>
<td>........</td>
<?php }?>
There is a problem with your SELECT query that's why it through error on mysql_fetch_array , try this way & use % if you want to match like '$login_session%' or '%$login_session' or '%$login_session%'
$emp_query=mysql_query("SELECT * FROM `history` WHERE user LIKE '".$login_session."'");
NB: move on to mysqli or PDO as adeneo advised
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:
Reference - What does this error mean in PHP?
(38 answers)
Closed 9 years ago.
I have small errors when I add date to my database.
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\chemmad\register.php on line 17.
But it works fine in my web server, but it is not working from local host.
mysql_num_rows is deprecated and you should not use it.
The correct way to count the number of rows in php is:
$db = new PDO( ... db connection details ...);
$q = $db->query('SELECT a, b, c FROM tbl WHERE oele = 2 GROUP BY boele');
$rows = $q->num_rows;
print $rows;
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.