有沒有辦法當我點擊一個按鈕時它會執行一堆php代碼?JS OnClick會執行php代碼塊的事件
例如;
<input type="button" value="Submit Order" class="minibutton" **onClick="executePHP"**>
這個按鈕對象就在這裏,如果我點擊它,這個php代碼將被執行。
include("../includes/connect.php");
include("../includes/generateTimestamp.php");
include("../includes/knowthename.php");
$pid=$_POST['submit_id'];
$pname = $_POST['submit_name'];
$total = $_POST['submit_total'];
$quantity = $_POST['submit_qty'];
$price = $_POST['submit_price'];
$unit = $_POST['submit_unit'];
$change = $_POST['submit_sukli'];
$payment = $_POST['submit_payment'];
$count = $_POST['count'];
//explode
$newpid = explode(";",$pid);
$newpname = explode(";",$pname);
$newquantity = explode(";",$quantity);
$newprice = explode(";",$price);
$newpriceunit = explode(";",$unit);
$sql = mysql_query("INSERT INTO sales (sales_date, total_price, emp_id) VALUES ('$timestamp','$total', '$employee_id')");
mysql_query($sql);
$id_gen = mysql_insert_id();
$count = $count - 1;
while($count = -1){
$product_id = $newpid[$count];
$product_name = $newpname[$count];
$product_quantity = $newquantity[$count];
$product_price = $newprice[$count];
$sql2("INSERT INTO sales_details (sales_id,product_id,sales_qty,unit_price,net_price) VALUES ('$id_gen','$newpid[$count]','$product_quantity[$count]',
'$product_price[$count]','$newpriceunit[$count]')");
mysql_query($sql2);
}
header('Location: prompt.php?x=5');
}else{
echo 'Nothing here!';
}
我想要做的onclick功能的斷路器,如果我點擊它,它就會別讓並繼續執行這些一串代碼,
如果沒有辦法,我能做到這一點,是有其他方法?
函數isset不起作用,因爲數據將會因爲原始數據來自$ _POST而丟失(數組)。我的希望是onclick事件,但我不知道如何。
請賜教我電腦的風險!
我會說這可能可以用一個jQuery/Ajax請求完成 - http://api.jquery.com/jQuery.ajax/ – Batfan