This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Closed 6 years ago.
what is error in this code output is
Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\xamp\htdocs\LMS\LMS\all_books.php on line 60
<?php
$sql1=mysql_query("SELECT COUNT(*) FROM book_list where book_id=$id AND status=0 AND item_type=0 AND condition='new'");
$count1 = mysql_result($sql1, 0, 0);
echo $count1;
?>
The function mysql_result() expects a resource (a mysql result-set) as its first parameter but has instead been supplied with a boolean (true/false) value.
This is likely because your SQL query is malformed (condition is a reserved keyword); You ought to enclose your table and column names in backticks, for example:
SELECT COUNT(*) FROM `book_list` WHERE `book_id`=$id AND `status`=0 AND `item_type`=0 AND `condition`='new'
Related
This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
One of my MySQL columns contains a hyphen. While the query works fine when tested through a mysql browser, it returns the key rather than the value when using using php mysqli_fetch_array($result).
The query I am running looks like this:
if($test_base_name==='isolation-mer') {
$test_name="`".$ds_channel[$i]."_isolation-mer`";
}
else {
$test_name=$ds_channel[$i]."_isolation-mer";
}
$query="select serial_number, $test_name from table_name";
if($result=mysqli_query($dbc,$query)) {
while($row=mysqli_fetch_arrya($result) {
$sid=$row['serial_number'];
$pass_fail=$row[$test_name];
...
The serial number is retrieved successfully. However, the $pass_fail variable always retrieves nothing. The test name is embedded with quotes. Even if I hardwire the key name within all kinds of quotes, it always retrieves the key and not the value.
This is an old version of PHP and I wonder if that is the issue. Perl has no issues with this.
PHP reads the below code as a variable and not as the name of your database column:
$pass_fail=$row[$test_name];
The below code should work:
$pass_fail=$row['$test_name'];
Using ...
select serial_number, 'isolation-noise' from table_name
means that 'isolation-noise' is a literal value which is selected and will return a result set of (e.g.)
1234,'isolation-noise'
1235,'isolation-noise'
whereas...
select serial_number, `isolation-noise` from table_name
using backticks, will return the actual value of the column.
Update:
When doing the assignment - you definitely shouldn't have backticks in the name of the field, so
$test_name=$ds_channel[$i]."_isolation-mer";
$query="select serial_number, `$test_name` from table_name";
if($result=mysqli_query($dbc,$query)) {
while($row=mysqli_fetch_arrya($result) {
$sid=$row['serial_number'];
$pass_fail=$row[$test_name];
So this always puts backticks round column name in the select statement and uses the raw name in fetching the data from the result set.
This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 6 years ago.
My code is as following:
$br_code=$_SESSION["br_code"];
echo $sqlstr="select DISTINCT branch_assets.s_id,s_name
from branch_assets,assets
where assets.s_id=branch_assets.s_id and
br_code='$br_code'";
echo $result=mysql_query($sqlstr);
while($row1=mysql_fetch_array($result))
{
}
But on the line of while loop it show me warning as
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\System_management\send_in_maintanance1.php
where is my mistake please help to find this.
$sqlstr="select DISTINCT branch_assets.s_id,s_name from branch_assets,assets where assets.s_id = branch_assets.s_id and br_code='".$br_code."'";
It's best to switch to either mysqli or PDO with a prepared statement instead of mysql_, since it is deprecated and deleted from PHP 7.0.
Reference:
https://en.wikipedia.org/wiki/Prepared_statement
This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 6 years ago.
I have users who add rows into db. Right above their picture I show the count of the rows they added. Pretty simple and it works fine. The problem is that I also get error which doesn't make sense:
mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in...
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
$result = mysqli_query($con,"SELECT * FROM my_table WHERE user_ids = ".
$row['user_id']."");
$reput = mysqli_num_rows($result);
}
$query works fine too, any idea how to satisfy the error?
You should use single quotes when calling something that isn't a boolean
WHERE user_ids = '".$row['user_id']."'"
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 supplied argument is not a valid MYSQL result
(4 answers)
Closed 9 years ago.
$query_user2 = mysql_query("SELECT TOP 1 * FROM $var WHERE id = (rand() * (SELECT MAX(id) FROM $var))");
$estrai2 = mysql_fetch_array($query_user2);
Problem: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
Why? :/
TOP 1 is a sql server ( not MySQL ) command to select the first row, remove that and add LIMIT 1 to the end of the query.
you might want to alter your question. The problem is your query, not the "supplied argument is not a valid mysql result"