Search code examples
javascriptphpconfirmation

Confirmation Box doesnt show and automatically delete


HELP ME Please. I created a delete process wherein there i a confirm box to ask the user if he is sure or not. but the confirm box doesnt appear and automatically deletes the data and doesnt even redirect me. Help me plss!

I need to show the confirmation box ("are u sure") and if the input is true. it will delete the data and redirect to other page.

 <?php
 require_once('connect/connect.php');
 ?>
 <script>
 var r = confirm("Are you sure?");
 if (r == true)
 {
 alert(' item successfuly deleted!!');
 </script>
 <?php

 if(isset($_GET['pid'])){
$sql ='Select * FROM product where pid = '.$_GET['pid'];
$qry = mysql_query($sql);
$data = mysql_fetch_array($qry);
$pname = $data['pname'];
$pstock = $data['pstock'];
}
$sq3="INSERT INTO report VALUES('NULL','".$pname."', '" .$pstock. "', 'Item Deleted' )";
$qry3 = mysql_query($sq3);

$sql2 = 'DELETE FROM product where pid = '.$_GET['pid'];
$qry2 = mysql_query($sql2);
?>
<script>
 window.location.assign('products.php');    
 }
 </script>
 <script>
 else
 {
window.location.assign('products.php');
 }
</script>

Solution

  • you missed the closing brace } of if condition

     <script>
     var r = confirm("Are you sure?");
     if (r == true)
     {
     alert(' item successfuly deleted!!');
     }
     </script>
    

    FIDDLE