有没有办法当我点击一个按钮时会执行一堆 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 事件,但我不知道如何。
请各位电脑高手赐教!