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
  • 28,454
  • 37
  • 55
  • 73
thomashoareau
  • 99
  • 1
  • 1
  • 10

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
  • 67,715
  • 15
  • 98
  • 113
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
  • 26,538
  • 10
  • 45
  • 61