Warning: mysql_fetch_assoc() Error [duplicate] - php

This question already has an answer here:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given
(1 answer)
Closed 8 years ago.
Im receiving the following error:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given

$getholidays isnt the result of getholidayrequest()
or
from the documentation:
mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query

you should check the mysql_query return value
$result = mysql_query('SELECT * WHERE 1=1');
if (!$result) {
die('RequĂȘte invalide : ' . mysql_error());
}

Related

PHP warning expects parameter 1 to be resource, object given [duplicate]

This question already has answers here:
Can I mix MySQL APIs in PHP?
(4 answers)
Closed 1 year ago.
I want to retrieve all data from a table, so I use this code
<?php
include("config.php");
$sql = "SELECT * FROM ".$USERS;
$sql_result = mysqli_query($connection, $sql);
if ($sql_result) {
while ($result = mysql_fetch_assoc($sql_result)) {
echo $result;
}
}
else {
die ('Could not execute SQL query '.$sql);
}
?>
but got this warning:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource,
object given in C:\xampp\htdocs\newSDP\phpscript\users.php on line 6
How can I fix it?
Change:
mysql_fetch_assoc to mysqli_fetch_assoc

Why is my PHP Mysqli code expecting a mysqli_result parameter [duplicate]

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 6 years ago.
I have a line of code in my php that reads:
$sel_venue = "SELECT 'char_type' FROM 'character_type_allowed' WHERE status='Open'";
$run_venue = mysqli_query($con,$sel_venue);
while ($row = mysqli_fetch_array($run_venue))
if ($row['char_type'] == 'Mortal')
{ print ("<li><a href='http://houston-by-night.com/sheets/create/mortal.php'>Create Mortal</a></li>"); }
The link associated with this does nothing. Zero interaction beyond acting likeit wants to expand. My error log produces this: Why is it asking for this?
[08-Aug-2016 23:28:41 America/New_York] PHP Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/houchat/public_html/incl/creation.php on line 8
You can't use ' as ticks for field/tablenames.
Your query is producing an error. You can see the error with mysqli_error($con).
Please see the corrected code below
$sel_venue = "SELECT `char_type` FROM `character_type_allowed` WHERE status='Open'";
$run_venue = mysqli_query($con,$sel_venue) or die(mysqli_error($con));
while ($row = mysqli_fetch_array($run_venue)) {
if ($row['char_type'] === 'Mortal') {
print ("<li><a href='http://houston-by-night.com/sheets/create/mortal.php'>Create Mortal</a></li>");
}
}
Your query failed, so $run_venue is the boolean false instead of what you expect. You should check for errors before you use any query result. Do this:
$run_venue = mysqli_query(...);
if(!$run_venue) die(mysqli_error($con));
... //<- we get here if the query succeeded
You will see the error. The problem is that your SQL statement wraps the table name between single quotes 'character_type_allowed', instead of backticks (backtick is above the tab key on my keyboard)

Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given [duplicate]

This question already has answers here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
INSERT query produces "Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given"
(2 answers)
Closed 2 years ago.
Why am I getting this error message:
Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given
My code is:
$statement = "INSERT INTO table1 (data1, data2) VALUES ('$variable1', '$variable2')";
if ($result = mysqli_query($conn,$statement)) {
echo "New record added successfully";
} else {
echo "Error adding records: " . $result . "<br>" . mysqli_error($conn);
}
echo "Adding records finished. ";
mysqli_free_result($result);
As stated in the mysqli_query manual:
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.
Your insert query will return true or false, but not an object. So, calling mysqli_free_result will not work here.

sqlsrv_fetch_array() expects parameter 1 Error using store procedure [duplicate]

This question already has answers here:
sqlsrv_fetch_array() expects parameter 1 to be resource, boolean given in
(3 answers)
Closed 7 years ago.
It is not dublicated question. im trying print records from my db (IIS, MSSQL PHP) but i have this error...
<?php
require_once 'connection.php';
$uspCall_Actividades="call usp_SelectCountActividades()";
/*Executando el query*/
$rsActividad=sqlsrv_query($connection1,$uspCall_Actividades);
while ($objRs=sqlsrv_fetch_object($rsActividad)){
echo($objRs->cantidad);
}
?>
Error: Warning: sqlsrv_fetch_object() expects parameter 1 to be resource, boolean
Change:
$uspCall_Actividades="call usp_SelectCountActividades()";
to use {} brackets:
$uspCall_Actividades="{call usp_SelectCountActividades()}";
You should also always wrap the while in a check
if($rsActividad === false) {
echo "Error in executing statement 3.\n";
die( print_r( sqlsrv_errors(), true));
} else {
while (...) {
...
}
}
Also specify any parameters you need:
$params = array(
array($text, SQLSRV_PARAM_OUT)
);
$rsActividad=sqlsrv_query($connection1,$uspCall_Actividades,$params);

mysql_num_rows(): supplied argument is not a valid MySQL result resource [duplicate]

This question already has answers here:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result [duplicate]
(6 answers)
Closed 9 years ago.
if(mysql_num_rows($result))
{
echo "no match found!";
}
it is throwing an error-
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\Hosting\6448289\html\includes\getQuestion.php on line 72
You need to check the return value of mysql_query
$query = 'YOUR QUERY';
$result = mysql_query($query);
if (!$result) {
trigger_error('Invalid query: ' . mysql_error()." in ".$query);
}
// go ahead and fetch the results using mysql_num_rows.
If mysql_query fails it returns boolean false instead of a resource.
When you pass this boolean value to mysql_num_rows you get this error.

Categories