Is there a way that when I click a button it will execute a bunch of php codes?
For example;
<input type="button" value="Submit Order" class="minibutton" **onClick="executePHP"**>
This button object right here if I click it this php codes will be executed.
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!';
}
I wanna make the onclick function as a breaker that if I click it, It will unbreak and continue to execute those bunch of codes,
If there is no way I can do that, is there other ways?
function isset won’t work because the data will be lost(arrays) because the original data came from $_POST. My hope is the onclick event but i don’t know how.
Please enlighten me wizzards of computer!
You can only attach JavaScript to browser events. If you want to execute server-side code such as PHP, you need to make a call to the server. In your situation, forget javascript and just POST your form to your PHP page.
then put your code in
file.phpEdit
Put all your post data in a hidden form fields. Then when you click the button, it will resubmit the post data.
If you have a multi-dimensional post array, just
serialize()it, stick it in 1 fieldthen
unserialize()it on the other side.