Insert Query Produces "Warning: MySQLi_Num_Rows() Expects Parameter 1 to Be MySQLi_Result, Boolean Given"

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



Leave a reply



Submit