Home > Mobile >  Echo script alert not working after mysqli query
Echo script alert not working after mysqli query

Time:02-04

if(isset($_POST['placeorder']))  //if user clicks button
{
  $date=date("Y-m-d");
   //insert query
  $order=mysqli_query($conn,"INSERT INTO tbl_orders(`user_id`,`p_id`,`p_img`, `p_name`, `p_price`, `quantity`, `total_price`, `order_date`, `is_delivered` ) SELECT `user_id`, `p_id`, `p_img`, `p_name`, `p_price`, `quantity`, `total_price`,'$date','NO'
  FROM tbl_cart where user_id='$userid'
  ORDER BY cart_id ASC ") or die(mysqli_error($conn));

  //delete query from tbl_cart
  mysqli_query($conn,"DELETE FROM `tbl_cart` WHERE `tbl_cart`.`user_id` = '$userid'") or die(mysqli_error($conn));
  
  //echo script to show alert and redirect to userorders page...both not working
  if($order)
  {
  echo "<script>alert(Order placed 
  successfully');window.location.href='userorders.php';</script>";
  }
}

the echo script statements are not working but the both mysqli_insert and delete queries are working fine

CodePudding user response:

You have a syntax error:

echo "<script>alert('Order placed successfully');window.location.href='userorders.php';</script>";

Btw. Your query looks very insecure for me.

  •  Tags:  
  • Related