<?
include("dbconnect.php");
if($submit == 'Add Case(s) To Cart')
{?>
<SCRIPT LANGUAGE="JavaScript">
var qty = "<?echo $qty;?>";
var price = "<?echo $price;?>";
var pack =  "<?echo $pack;?>";
var total = (pack * price);
var casetotal = (total * qty);
if (confirm("*** This is a Case Only Item ***\n\nThis means that the quantity you enter\nwill be the amount of case you buy and\nnot the amount of pieces.\n\n\t"+price+"\tCase Price\n\tx"+pack+"\tCase Pack\n\t-------------\n\t"+total+"\tUnit Total\n\tx"+qty+"\tQuantity\n\t-------------\n\n\t$"+casetotal+"\tOrder Total For This Item\n\nDo you want "+qty+" case(s) of this item?"))
{
}
else
{
history.go(-1);
exit;
}   
</SCRIPT> <?} $query = "select * from storeOrders where orderCustomerID = '$custID' and orderStatus = 'Pending'"; $mysql_result = mysql_query($query, $mysql_link); $recordCount = 0; $recordCount = mysql_affected_rows ($mysql_link); if($recordCount == 0) { srand(time()); $orderNumber = (rand()%10000)+1; } else { while($row = mysql_fetch_row($mysql_result)) { $orderNumber = $row[1];} } $query = "select * from storeOrders where orderCustomerID = '$custID' and orderStatus = 'Pending' and orderProductID = '$productID'"; $mysql_result = mysql_query($query, $mysql_link); if(mysql_affected_rows() != 0) { print("<h2>Cannot Add Product Twice!</h2>\n<b>Please Change Quantities <a href=\"store.php?myAccount=My+Cart\">here</a></b>."); exit(); } else { $query = "insert into storeOrders (orderNumber, orderStatus, orderCustomerID, orderProductID, orderQuantity)values"; $query .= "('$orderNumber', 'Pending', '$custID', '$productID', '$qty')"; $mysql_result = mysql_query($query, $mysql_link); } ?>

Shouldn't the javascript wait for a reply from the confirm box before is finishes this script??

It doesn't...once the box pops up, the item is already entered into the database as per the $query right below it.

Is there a way to stop this?

    Hi There

    you've been tripped up by the difference between serverside and client side processing.

    there is nothing in your script to say, "hey, stop processing until I submit again"

    I think you need to structure it slightly differently...

    <?php
    if($submit == 'Add Case(s) To Cart')
    {
    // break out and put the javascript up
    }
    else
    {
    //query the database and feedback if ok...
    }
    ?>
    

      I had already thought about that, but the problem is....

      I submit from another page and depending on what some varialbes are from that page, depends on how it submitted (you would have to see the whole thing to understand).

      in the if(confirm){} I left it blank hoping at that point that it would then submit back throught and finish the script.

      I understand about server and client side, I just thought that when you click ok on the confirm that it resubmits.

      I can't put the javascript in with everything else because the case is not always Add Case(s) To Cart, it is often something else.

      I can't do window.location, because of the way everything is set up, if the variables are all passed again, it would completely screw up the database.

      Thanks for the thought though, I was just hoping there was a way to hold the server script until the confirm is resubmitted.

        Write a Reply...