Job Sanjuan Job Sanjuan - 1 month ago 10
MySQL Question

setting the row inactive by getting its database id

delete.php

I want to change my delete that when i delete a record on my website it will not be permanently deleted on my database I already made an additional column(

status INTEGER NOT NULL DEFAULT 0
) that when 0=inactive(deleted) 1=active

<?php
include_once 'dbconfig.php';

if($_POST['del_id']){
$id = $_POST['del_id'];
$stmt=$db_con->prepare("DELETE FROM tblsales WHERE id=:id");
$stmt->execute(array(':id'=>$id));
}
?>


thanks for the help I'm just starting my php

Answer

Simply change your query to an update query:

  $stmt=$db_con->prepare("UPDATE tblsales set status=0 WHERE id=:id");
  $stmt->execute(array(':id'=>$id));   

BTW: I think your Default should be 1 (active)?