I purposely did not include any code as this is more a conceptual question than a coding question. But, if you think it will help, here's the code:
session_start();
include('db.php');
function countCart() {
$query = "select count(*) from cart where cookieId = '".GetCartId()."'";
$result = mysql_query($query) or die("Error counting items in cart: ".mysql_error());
$count = mysql_fetch_row($result);
if($count[0] >= 1){
return true;
}
else{
return false;
}
}
if($_SESSION['user_logged_in'] != "true"){
header("Location: signin.php");
}
else if(countCart() != true){
header("Location: store.php");
}
else{
include('site_tools/dopayment.php');
}
and here's dopayment.php:
function generateOrder(){
$query = "insert into orders(orderID, shippingAddress1, shippingAddress2, contactNumber, dispatchDate, orderCost, orderTax,
shippingCost, orderTotalCost, orderDate, orders_clientId) values(0, '".$_SESSION['shipAddress1']."', '".$_SESSION['shipAddress2']."', '".$_SESSION['clientPhone']."',
'today', '50', '50', '50', '50', 'today', '".$_SESSION['clientId']."')";
if(mysql_query($query)){
$_SESSION['orderId'] = mysql_insert_id();
return true;
else {
return false;
}
}
function createJobs(){
$getQuery = "select * from cart where cookieId = '".GetCartId()."'";
$result = mysql_query($getQuery);
while($row = mysql_fetch_array($result)){
$moveQuery = "
insert into frameJobs(jobId, userImage, userThumb, printSize, mouldingName, mouldingNumber, topMatName, topMatNumber, bottomMatName, bottomMatNumber, itemCost, frameJobs_orderId, jobQuantity)
values('0', '".$row['userimage']."', '".$row['thumbImage']."', '".$row['size']."', '". $row['moulding_name'] . "',
'".$row['mldg_number']."', '".$row['t_mat_value']."', '".$row['t_mat_number']."', '".$row['b_mat_value']."',
'".$row['b_mat_number']."', '".$row['price']."', '".$_SESSION['orderId']."', '" . $row['qty'] . "')";
mysql_query($moveQuery) or die("Error creating jobs: " . mysql_error());
}
return true;
}
function clearCart(){
$query = "delete from cart where cookieId = '" . GetCartId() . "'";
mysql_query($query) or die("Error clearing cart: ".mysql_error());
}
function clearOrder(){
$query = "delete from orders where orderId = '" . $_SESSION['orderId'] . "'";
$query2 = "delete from frameJobs where frameJobs_orderId = '" . $_SESSION['orderId'] . "'";
mysql_query($query);
mysql_query($query2);
}
function processCard(){
return true;
}
if(processCard() && generateOrder() && createJobs()){
$_SESSION['paymentStatus'] = "Card authorized";
clearCart();
include('site_tools/send_confirm.php');
mailInvoice($_SESSION['clientId'], $_SESSION['orderId']);
}
else {
clearOrder();
$_SESSION['paymentStatus'] = "Card not authorized Jerk";
}