1

Why is my MySQLi query returning bool(false)?

require_once("LinkDB.php");
$noCommande = $_POST['noCommande'] ;
$req = "Delete From transactions Where no_Commande = ".$noCommande;
require 'config.php';
$connexion = LinkDB::get();

if (!$connexion) 
{

}

if ($connexion)
{   
    $resultat = mysqli_query($connexion,$req) ;
    var_dump($resultat);
    var_dump($req);
}
showdev
  • 27,301
  • 36
  • 51
  • 71
thomashoareau
  • 99
  • 1
  • 1
  • 9

2 Answers2

2

As you can see in the documentation:

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.

For DELETEqueries the return false if the query failed.

So that indicates that your query has an error. Call mysqli_error($connexion)); to see the error message.

Community
  • 1
  • 1
Jens
  • 63,364
  • 15
  • 92
  • 104
0

$noCommande is string, it came from form. You forgot quotes around it.

$req = "Delete From transactions Where no_Commande = '" . $noCommande . "'";

Or, if you send a number in form, you can change variable type.

$req = "Delete From transactions Where no_Commande = " . (int)$noCommande;
pavel
  • 25,361
  • 10
  • 41
  • 58