简体   繁体   中英

Why is my MySQLi query returning bool(false)?

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);
}

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 DELETE queries 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.

$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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM