1

I got a function that should return true or false:

public function SetActiveStatus($DB_CON, $TABLE_NAME, $ITEM_INDEX, $NEW_STATUS)
{
strSQL="UPDATE empresa." . $TABLE_NAME ." SET cat_Active = " . $NEW_STATUS . " WHERE idtbl_Cats = ". $ITEM_INDEX . ";";

return mysqli_query($DB_CON, strSQL);

}

now, if i put a correct table name, changes on data base are applied and returns true. but, if I input, on purpose, a bad table name nothing happens, no even an error, and it doesn't return a false value

if(SetActiveStatus(MyConn, "realTableName", any_int_number, true_or_false)){
                            $data['msg']= "Update successful";
                        }else{
                            $data['msg']= "Update unsuccessful";
                        }

it just ignore the else part and finish. anyone know what is happening?

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • Per the documentation, [`mysqli_query`](https://www.php.net/manual/en/mysqli.query.php), returns _false on failure_… otherwise a _mysqli_result object_, so your first statement is not correct. Now, that function might be coerced into a boolean, but that’s a different thing – Chris Haas Jun 04 '22 at 02:12
  • if any error happens no matter wich is the error i want the return to be false, can it be done? – Ulises Lopez Jun 04 '22 at 02:18
  • @ChrisHaas for this `UPDATE` query, or any which don't produce a result set, the return will be `true` on success. – msbit Jun 04 '22 at 02:33
  • it is correct @msbit. And it supossed to return false on error. but it doesn't. a bad table name supposed to throw an error on mysqli_query excecution. – Ulises Lopez Jun 04 '22 at 02:37
  • So it does. Which makes this condition essentially useless – Your Common Sense Jun 04 '22 at 03:49
  • Please read the answer to the question linked at the top. It will explain what is going on. – Your Common Sense Jun 04 '22 at 04:09
  • @YourCommonSense thanks for the reference. i'll check the post. – Ulises Lopez Jun 04 '22 at 17:09

0 Answers0