HTML(menu.php)
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php echo $result; ?> //result alert
</div>
</div>
这是用于从process.php调用警报引导程序的代码。 所以当我从php点击按钮时,process.php将检查它并返回menu.php。警报应该显示成功或失败。
PHP(process.php) 整个过程.php
<?php
include('../koneksi.php');
session_start();
$hasilp=MySQL_query ("select * from tb_pin Where id_pin='$_SESSION[id_pin]'");
$datap=mysql_fetch_array ($hasilp); //var
$hasilm=MySQL_query ("select * from tb_menu Where id_menu='$_GET[id_menu]'");
$datam=mysql_fetch_array ($hasilm); // var
$max= "SELECT MAX(jumlah_pemesanan) AS record FROM tb_pemesanan where id_pin='$datap[id_pin]'";
$query_max =mysql_query($max);
if ($query_max) {
$max_r= mysql_fetch_assoc($query_max);
$max_temp= $max_r['record']+1;
}
//Cek Result zero
$cek= mysql_query("SELECT id_menu FROM tb_pemesanan_temp WHERE id_menu='$datam[id_menu]' AND id_pin='$datap[id_pin]'");
if (mysql_num_rows($cek) > 0) {
$hasilj=MySQL_query ("select jumlah from tb_pemesanan_temp Where id_menu='$datam[id_menu]' AND id_pin='$datap[id_pin]'");
$dataj=mysql_fetch_array ($hasilj); //var
$newjumlah= $dataj['jumlah'] + 1; //add 1 to jumlah
$total = $datam['harga_menu'] * $newjumlah; //total
$update= "UPDATE tb_pemesanan_temp SET id_pin='$datap[id_pin]', id_menu='$datam[id_menu]',
jumlah='$newjumlah', total_harga='$total' WHERE id_menu='$datam[id_menu]' AND id_pin='$datap[id_pin]'";
$query_update =mysql_query($update); //update data
if ($query_update) {
$result='<div class="alert alert-success">Thank You! I will be in touch</div>'; //alert success
} else {
$result='<div class="alert alert-danger">Thank You! I will be in touch</div>'; //alert fail
}
}else{
$input= "INSERT INTO tb_pemesanan_temp (id_pin, no_meja, jumlah, total_harga, status, keterangan, id_menu, nama_menu, jenis_menu, harga, jumlah_pemesanan)
VALUES ('$datap[id_pin]','$datap[no_meja]','1','$datam[harga_menu]','Sedang di proses','-','$datam[id_menu]','$datam[nama_menu]','$datam[jenis_menu]','$datam[harga_menu]','$max_temp')"; //insert data
$query_input =mysql_query($input);
if ($query_input) {
$result='<div class="alert alert-success">Thank You! I will be in touch</div>'; //alert success
} else {
$result='<div class="alert alert-danger">Thank You! I will be in touch</div>'; //alert fail
}
}
?>