
December 26th, 2002, 10:22 PM
|
|
Contributing User
|
|
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97
Time spent in forums: 23 m 33 sec
Reputation Power: 6
|
|
PHP Code:
<body topmargin="0">
<?
if($UserLoggedIn) // If user is registered and logged in.
{
?>
<?php
$IP = getenv("REMOTE_ADDR");
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("database",$db);
if ($_POST["Submit"] == "Purchase") // when Purchase button is pressed
{
$itemid = $_POST["itemid"] ;
$qty = $_POST["qty"] ;
$orderid = uniqid();
//Inserts records into USERORDER table
$records = array($itemid, $qty);
for ( $i = '1'; $i <= count( $records ); $i++ ) {
//echo $records[1];
mysql_query("INSERT INTO userorder (UserID, itemId, qty, IpAddress, PaymentStatus, TimeKey,OrderDate,GrandTotal) VALUES ('$details[0]', '$records[0]', '$records[1]', '$IP', 'Pending', " . time().", NOW(''), " . $_POST['Total'] . ")");
}
//header("location: redirect.php?orderid=$orderid&Total=" . $_POST['Total'] . "");
}
$query_record = sprintf("select * from cart inner join items on cart.itemid = items.itemId where cart.cookieid = '%s' ", $_COOKIE["cartId"]);
$result = mysql_query($query_record, $db);
?>
<form action="pay.php?purchase=yes" method="post" name="frmPay" id="frmPay" >
<table width="600" border="0" align="center" cellpadding="1" cellspacing="0" class="TableMain">
<tr>
<td colspan="4" align="center"></td>
</tr>
<tr>
<td width="144"><font color="#FFFFFF"><strong> Quantity</strong></font></td>
<td width="9"><font color="#FFFFFF"> </font></td>
<td width="288"><font color="#FFFFFF"><strong>Package</strong></font></td>
<td width="151"><font color="#FFFFFF"><strong>Price</strong></font></td>
</tr>
<tr>
<td colspan="4" align="center"></td>
</tr>
<? while ($myrow = mysql_fetch_array($result))
{
$Total += ($myrow["qty"] * $myrow["itemPrice"]);
?>
<tr>
<td width="144"><font color="#FFFFFF"></font><?php echo $myrow['qty']; ?>
<input name="qty" type="hidden" id="qty" value="<?php echo $myrow['qty']; ?>">
</td>
<td> </td>
<td width="288"><?php echo $myrow['itemName']; ?></td>
<td width="151">$<?php echo $myrow['itemPrice']; ?> <input name="itemid" type="hidden" id="itemid" value="<? echo $myrow['itemId'];?>"></td>
</tr>
<tr>
<td colspan="4" align="center"></td>
</tr>
<tr>
<?php
} //end while loop
?>
<td width="144"> </td>
<td> </td>
<td width="288" align="right"> </td>
<td width="151"> </td>
</tr>
<tr>
<td colspan="4" align="center"></td>
</tr>
</table>
<table width="94%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="30%" align="center"> <input name="cart" type="button" class="SubmitButtons" id="cart" value="Return to Cart" onClick="javascript: location.replace('cart.php')">
</td>
<td width="44%" align="center"><strong><font color="#FFFFFF">Total:</font>
$<? echo number_format($Total, 2, ".", ","); ?> </strong></td>
<td width="24%" align="center"><input name="Total" type="hidden" id="Total" value="<? echo number_format($Total, 2, ".", ","); ?>">
<input name="Submit" type="submit" class="SubmitButtons" value="Purchase">
</td>
</tr>
<tr>
<td colspan="4" align="center"></td>
</tr>
</table>
</form>
<? } else {
// If user is NOT registered
header( "location: login.php");
}
?>
</body>
|