INSERT query produces Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
The mysqli_num_rows()
function returns the number of rows in a result set. For insert, update and delete use mysqli_affected_rows
mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean with mysqli
According to another question here :
The INSERT
command will return a boolean(true/false), So you must use select command to get the required result
PHP & MySQL: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
$dbc
is returning false. Your query has an error in it:
SELECT users.*, profile.* --You do not join with profile anywhere.
FROM users
INNER JOIN contact_info
ON contact_info.user_id = users.user_id
WHERE users.user_id=3");
The fix for this in general has been described by Raveren.
mysqli_num_rows returns false but data is added to database
From the documentation for the get_result()
function (emphasis mine):
Returns a resultset for successful SELECT queries, or FALSE for other DML queries or on failure.
You're executing an INSERT
query, so get_result()
will return false
.
Instead, you should be using the mysqli_stmt_*
functions (or just access the properties directly) to obtain information about the query's result from your $sql_sec
statement directly:
if(mysqli_stmt_affected_rows($sql_sec)){
// or:
if($sql_sec->affected_rows) {
Note that you need to check the affected_rows
property, not the num_rows
property. The reason is that num_rows
returns the number of rows in the result set. You're not selecting a result set, you're inserting a new set of data. That means you're actually interested in the number of rows that was inserted, which is stored in the affected_rows
property.
SQL PHP Error: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
This is because $conn->query($sql);
returned FALSE
. Your call $conn->query($sql);
was not successful.
You have an error in your syntax:
$sql = "SELECT * FROM tbl_flights WHERE pilot_initial_post IS NULL OR = '' AND is_deleted = '0'";
should be changed to
$sql = "SELECT * FROM tbl_flights WHERE (pilot_initial_post IS NULL OR pilot_initial_post = '') AND is_deleted = '0'";
The OR operator requires the field_name.
And for debugging add or die(mysqli_error($conn));
to your $conn->query($sql);
call.
Related Topics
Does the Order of Class Definition Matter in PHP
PHP String Interpolation Syntax
Updating Product Stock Programmatically in Woocommerce 3
PHP Localization Best Practices? Gettext
Inserting Line Breaks into PDF
How to Set Cron Job Through PHP Script
Process Mathematical Equations in PHP
Is Is Bad Practice to Use Array_Walk with MySQLi_Real_Escape_String
How to Implement Ocr on a Website Using PHP
How to Call a PHP Function from Ajax
How to Use Array_Unique on an Array of Arrays
How to View/Open a Word Document in My Browser Using with PHP or HTML
Good Error Handling with File_Get_Contents
PHP Curly Braces in Array Notation
How to Install Composer on App Service