Devo9 Devo9 - 3 months ago 12
PHP Question

mysqli Delete query return boolean false

i'm waching a tutorial i'm trying to delete a specific section By Id , i'm gettin Error Processing Request which is my error exception in my model and if i var_damp my query it returns boolean false idk why this not working.

model

public function deletesec($id)
{
// Delete a specific section.
$query = "DELETE * FROM $this->tablename WHERE id = '$id'";

if (!$sqli = mysqli_query($this->cxn->connect(),$query)) {

var_dump($sqli);
throw new Exception("Error Processing Request");

}else
echo "Done";
}


controller

try
{
//Display all data.
require_once '../model/cone.php';
require_once '../model/display.php';
$display = new Display("sections");
$data = $display->getSections();

//Delete a specific section By Id.
if(isset($_GET['deleteid']))
{
$id = $_GET['deleteid'];
require_once '../model/dsections.php';
$delete = new Dsections("sections");
$delete->deletesec($id);
}

//my view.
require_once '../view/vsections.php';
}

Answer

Change the query by removing the *

$query = "DELETE  FROM $this->tablename WHERE id = '$id'";

Also check if you require those quotes around $id

Comments