The goal is to have a user select a past order and then "Reorder" the selected order. Being a n00b, I am pulling all of the data from the past order and reinserting the data with a newly generated orderID number. I am successfully adding the data to the tables, but when I advance on to the next page, a new orderID number is being generated and not the one that I just used. So when I referenced the "newOrderID" variable, the number is not correct. Code is below. Please let me know why this is. Thank you.
<?php
setcookie('newOrderID', rand(),time()+60*20);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>none</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<table width="100%">
<tr>
<td><a href="history.php">Back to Order History</a></td>
<td align="right"><a href="JavaScript:window.print();">Print Record</a></td>
</tr>
</table>
<?php
echo '<strong>PRODUCTS</strong>';
$host= ******* // Host name
$username="******"; // Mysql username
$password="*******"; // Mysql password
$db_name="*******"; // Database name
$tbl_name="OrderItems"; // Table name
$orderNo= "$_POST[orderID]";
$newOrderID=$_COOKIE['newOrderID'];
// Connect to server and select databse
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM OrderItems WHERE orderID = '$orderNo' AND productQuantity > 0";
$result=mysql_query($sql);
// Define $color=1
$color="1";
echo '<table width="440" border="0" align="center" cellpadding="3" cellspacing="0">
<th align="left"> </th>
<th align="left" width="40%">Product</th>
<th align="left">Unit Price</th>
<th align="left">Quantity</th>
<th align="left">Subtotal</th>
<th align="left"> </th>
';
while($rows=mysql_fetch_array($result)){
$quantity = $rows['productQuantity'];
$price = $rows['productPrice'];
$total = $quantity * $price;
$subTotal = $total + $subTotal;
$weight = $rows['productWeight'];
$subWeight = $quantity * $weight;
$totalWeight = $subWeight + $totalWeight;
$orderItemsID = $rows['orderItemsID'];
$orderID = $rows['orderID'];
$productID = $rows['productID'];
$productName = $rows['productName'];
$productPrice = $rows['productPrice'];
$productQuantity = $rows['productQuantity'];
$weight = $rows['productWeight'];
$shipPrice = $rows['price'];
$locationID = $rows['locationID'];
$facilityName = $rows['facilityName'];
$shippingID = $rows['shippingID'];
$shipment = $rows['orderLocationID'];
$con = mysql_connect("******","******","******");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("*****", $con);
mysql_query("INSERT INTO OrderItems (orderID, productID, productName, productPrice, productQuantity, productWeight)
VALUES ('$newOrderID', '$productID', '$productName', '$productPrice', '$productQuantity', '$weight')");
echo "Success";
echo "$newOrderID";
// If $color==1 table row color = #FFFFFF
if($color==1){
echo "<tr align='left' bgcolor='#FFFFFF'>
<td>
<input name='orderID' type='hidden' value='".$orderID."' /></td>
<td>".$rows['productName']."</td>
<td>$".$rows['productPrice']."</td>
<td>".$rows['productQuantity']."</td>
<td>$".$total."</td>
<td>
<input name='orderItemsID' type='hidden' value='".$orderItemsID."' />
<input name='productName' type='hidden' value='".$productName."' />
<input name='productPrice' type='hidden' value='".$productPrice."' />
<input name='locationID' type='hidden' value='".$locationID."' />
<input name='facilityName' type='hidden' value='".$facilityName."' />
<input name='shippingID' type='hidden' value='".$shippingID."' />
</td>
</tr>";
// Set $color==2, for switching to other color
$color="2";
}
// When $color not equal 1, use this table row color
else {
echo "<tr align='left' bgcolor='E1E1E1'>
<td>
<input name='orderID' type='hidden' value='".$orderID."' /></td>
<td>".$rows['productName']."</td>
<td>$".$rows['productPrice']."</td>
<td>".$rows['productQuantity']."</td>
<td>$".$total."</td>
<td>
<input name='orderItemsID' type='hidden' value='".$orderItemsID."' />
<input name='productName' type='hidden' value='".$productName."' />
<input name='productPrice' type='hidden' value='".$productPrice."' />
<input name='locationID' type='hidden' value='".$locationID."' />
<input name='facilityName' type='hidden' value='".$facilityName."' />
<input name='shippingID' type='hidden' value='".$shippingID."' />
</td>
</tr>";
// Set $color back to 1
$color="1";
}
}
echo "<tr>
<td></td>
<td><strong>Subtotal:</strong></td>
<td></td>
<td></td>
<td><strong>$" .$subTotal. ".00</strong></td>
</tr>";
echo '</table>';
mysql_close();
?>
<?php
// LOCATIONS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$host="*****"; // Host name
$username="****"; // Mysql username
$password="*****"; // Mysql password
$db_name="******"; // Database name
$tbl_name="OrderLocations"; // Table name
$orderNo= "$_POST[orderID]";
$newOrderID=$_COOKIE['newOrderID'];
// Connect to server and select databse
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM OrderLocations JOIN Locations USING(locationID) WHERE orderID = '$orderNo'";
$result=mysql_query($sql);
// Define $color=1
$color="1";
echo '<strong>LOCATIONS</strong>';
echo '<table width="440" border="0" align="center" cellpadding="3" cellspacing="0">
<th>Account#</th>
<th>Facility Name</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>Product Charges</th>
<th>Shipping Charges</th>
<th> </th>';
while($rows=mysql_fetch_array($result)){
$orderID = $rows['orderID'];
$orderLocationID = $rows['orderLocationID'];
$account = $rows['locationID'];
$facilityName = $rows['facilityName'];
$facilityCity = $rows['facilityCity'];
$facilityAddress = $rows['facilityAddress'];
$facilityState = $rows['facilityState'];
$facilityZip = $rows['facilityZip'];
$shipPrice = $rows['shipCost'];
$curVal = $shipPrice + $curVal;
$total = $curVal;
$con = mysql_connect("****","*****","*******");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("******", $con);
mysql_query("INSERT INTO OrderLocations (orderID, locationID, facilityName)
VALUES ('$newOrderID', '$account', '$facilityName')");
echo "Success";
echo "$newOrderID";
// If $color==1 table row color = #FFFFFF
if($color==1){
echo "<tr align='left' bgcolor='#FFFFFF'>
<td>
".$rows['locationID']."</td>
<td>".$rows['facilityName']."</td>
<td>".$rows['facilityCity']."</td>
<td>".$rows['facilityState']."</td>
<td>".$rows['facilityZip']."</td>
<td>$".$subTotal."</td>
<td>$".$rows['shipCost']."</td>
<td>
<input name='account' type='hidden' value='".$account."' />
<input name='facilityName' type='hidden' value='".$facilityName."' />
<input name='facilityAddress' type='hidden' value='".$facilityAddress."' />
<input name='facilityCity' type='hidden' value='".$facilityCity."' />
<input name='facilityState' type='hidden' value='".$facilityState."' />
<input name='facilityZip' type='hidden' value='".$facilityZip."' />
</td>
</tr>";
// Set $color==2, for switching to other color
$color="2";
}
// When $color not equal 1, use this table row color
else {
echo "<tr align='left' bgcolor='E1E1E1'>
<td>
".$rows['locationID']."</td>
<td>".$rows['facilityName']."</td>
<td>".$rows['facilityCity']."</td>
<td>".$rows['facilityState']."</td>
<td>".$rows['facilityZip']."</td>
<td>$".$subTotal."</td>
<td>$".$rows['shipCost']."</td>
<td>
<input name='account' type='hidden' value='".$account."' />
<input name='facilityName' type='hidden' value='".$facilityName."' />
<input name='facilityAddress' type='hidden' value='".$facilityAddress."' />
<input name='facilityCity' type='hidden' value='".$facilityCity."' />
<input name='facilityState' type='hidden' value='".$facilityState."' />
<input name='facilityZip' type='hidden' value='".$facilityZip."' />
</td>
</tr>";
// Set $color back to 1
$color="1";
}
}
echo '</table>';
mysql_close();
?>
<?php
$link = mysql_connect("*****", "*****", "*****");
mysql_select_db("****", $link);
$result = mysql_query("SELECT * FROM OrderLocations WHERE orderID = '$orderNo'", $link);
$num_rows = mysql_num_rows($result);
echo "$num_rows";
echo "<br />";
$grandTotal = $num_rows * $subTotal;
echo "Grand Total: ";
echo $grandTotal;
echo "<br />";
echo "Total Weight: ";
echo $totalWeight;
?>
<?
// PRINTS SHIPPING TOTAL
echo "<br />
Total Shipping Cost $";
echo $total;
// ADDS SHIPPING TOTAL AND PRODUCT TOTAL TO PRINT ORDER TOTAL
echo "<br />";
$orderTotal = $grandTotal + $total;
echo "Total Order Cost: $";
echo $orderTotal;
?>
<?php
echo '
<br />
'.$newOrderID.'
<br />
';
?>
</body>
</html>