I know ur not ere to do the work. I'm only asking for the solutions as this is the reason i'm post them online as i'm stuck. You want to know what happens in the sql db when delete button is clicked and whats displayed:
my tables is as follows:
Code: Select all
CREATE TABLE `tbl_order_item` (
`od_id` int(10) unsigned NOT NULL default '0',
`pd_id` int(10) unsigned NOT NULL default '0',
`od_qty` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`od_id`,`pd_id`)
) TYPE=MyISAM;
and:
Code: Select all
CREATE TABLE `tbl_order` (
`od_id` int(10) unsigned NOT NULL auto_increment,
`od_date` datetime default NULL,
`od_last_update` datetime NOT NULL default '0000-00-00 00:00:00',
`od_status` enum('New', 'Paid', 'Shipped','Completed','Cancelled') NOT NULL default 'New',
`od_memo` varchar(255) NOT NULL default '',
`od_shipping_first_name` varchar(50) NOT NULL default '',
`od_shipping_last_name` varchar(50) NOT NULL default '',
`od_shipping_address1` varchar(100) NOT NULL default '',
`od_shipping_address2` varchar(100) NOT NULL default '',
`od_shipping_phone` varchar(32) NOT NULL default '',
`od_shipping_city` varchar(100) NOT NULL default '',
`od_shipping_state` varchar(32) NOT NULL default '',
`od_shipping_postal_code` varchar(10) NOT NULL default '',
`od_shipping_cost` decimal(5,2) default '0.00',
`od_payment_first_name` varchar(50) NOT NULL default '',
`od_payment_last_name` varchar(50) NOT NULL default '',
`od_payment_address1` varchar(100) NOT NULL default '',
`od_payment_address2` varchar(100) NOT NULL default '',
`od_payment_phone` varchar(32) NOT NULL default '',
`od_payment_city` varchar(100) NOT NULL default '',
`od_payment_state` varchar(32) NOT NULL default '',
`od_payment_postal_code` varchar(10) NOT NULL default '',
PRIMARY KEY (`od_id`)
) TYPE=MyISAM AUTO_INCREMENT=1001 ;
.... from all the changes i've been doing, little errors came up but i fixed them. What comes up for so long in the output is that it looks like the page is just being refreshed and the order is not deleted. However, the same thing happened to your code that i put in. The sql db has not be changed while the order details are still in there.
ere's the processOrder.php
Code: Select all
<?php
require_once '../../library/config.php';
require_once '../library/functions.php';
checkUser();
$action = isset($_GET['action']) ? $_GET['action'] : '';
switch ($action) {
case 'modify' :
modifyOrder();
break;
case 'deleteOrder' :
deleteOrder();
break;
default :
// if action is not defined or unknown
// move to main order page
header('Location: index.php');
}
function modifyOrder()
{
if (!isset($_GET['oid']) || (int)$_GET['oid'] <= 0
|| !isset($_GET['status']) || $_GET['status'] == '') {
header('Location: index.php');
}
$orderId = (int)$_GET['oid'];
$status = $_GET['status'];
$sql = "UPDATE tbl_order
SET od_status = '$status', od_last_update = NOW()
WHERE od_id = $orderId";
$result = dbQuery($sql);
header("Location: index.php?view=list&status=$status");
}
/*
Remove an order
*/
function deleteOrder()
{
if (isset($_GET['oid']) && (int)$_GET['oid'] > 0){
$orderId = (int)$_GET['oid'];
} else {
header('Location: index.php');
}
// remove any references to this order from
// tbl_order_item
$sql = "DELETE FROM tbl_order_item, tbl_order
WHERE od_id = $orderId";
mysql_query($sql);
echo $sql .'<br>';
echo 'Affected rows: '. mysql_affected_rows();
header('Location: index.php');
}
?>
list.php
Code: Select all
<?php
if (!defined('WEB_ROOT')) {
exit;
}
if (isset($_GET['status']) && $_GET['status'] != '') {
$status = $_GET['status'];
$sql2 = " AND od_status = '$status'";
$queryString = "&status=$status";
} else {
$status = '';
$sql2 = '';
$queryString = '';
}
// for paging
// how many rows to show per page
$rowsPerPage = 10;
$sql = "SELECT o.od_id, o.od_shipping_first_name, od_shipping_last_name, od_date, od_status,
SUM(pd_price * od_qty) + od_shipping_cost AS od_amount
FROM tbl_order o, tbl_order_item oi, tbl_product p
WHERE oi.pd_id = p.pd_id and o.od_id = oi.od_id $sql2
GROUP BY od_id
ORDER BY od_id DESC";
$result = dbQuery(getPagingQuery($sql, $rowsPerPage));
$pagingLink = getPagingLink($sql, $rowsPerPage, $queryString);
$orderStatus = array('New', 'Paid', 'Shipped', 'Completed', 'Cancelled');
$orderOption = '';
foreach ($orderStatus as $stat) {
$orderOption .= "<option value=\"$stat\"";
if ($stat == $status) {
$orderOption .= " selected";
}
$orderOption .= ">$stat</option>\r\n";
}
?>
<p> </p>
<form action="processOrder.php" method="post" name="frmOrderList" id="frmOrderList">
<table width="100%" border="0" cellspacing="0" cellpadding="2" class="text">
<tr align="center">
<td align="right" style="color:#cc0033">View</td>
<td width="75"><select name="cboOrderStatus" class="box" id="cboOrderStatus" onChange="viewOrder();">
<option value="" selected>All</option>
<?php echo $orderOption; ?>
</select></td>
</tr>
</table>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="text">
<tr align="center" id="listTableHeader">
<td width="60">Order #</td>
<td>Customer Name</td>
<td width="60">Amount</td>
<td width="150">Order Time</td>
<td width="70">Status</td>
<td width="70">Delete</td>
</tr>
<?php
$parentId = 0;
if (dbNumRows($result) > 0) {
$i = 0;
while($row = dbFetchAssoc($result)) {
extract($row);
$name = $od_shipping_first_name . ' ' . $od_shipping_last_name;
if ($i%2) {
$class = 'row1';
} else {
$class = 'row2';
}
$i += 1;
?>
<tr class="<?php echo $class; ?>">
<td width="60"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?view=detail&oid=<?php echo $od_id; ?>"><?php echo $od_id; ?></a></td>
<td><?php echo $name ?></td>
<td width="60" align="right"><?php echo displayAmount($od_amount); ?></td>
<td width="150" align="center"><?php echo $od_date; ?></td>
<td width="70" align="center"><?php echo $od_status; ?></td>
<td width="70" align="center"><a href="javascript:deleteOrder(<?php echo $od_id; ?>);">Delete</a></td>
</tr>
<?php
} // end while
?>
<tr>
<td colspan="6" align="center">
<?php
echo $pagingLink;
?></td>
</tr>
<?php
} else {
?>
<tr>
<td colspan="6" align="center">No Orders Found </td>
</tr>
<?php
}
?>
</table>
<p> </p>
</form>
details.php
Code: Select all
<?php
if (!defined('WEB_ROOT')) {
exit;
}
if (!isset($_GET['oid']) || (int)$_GET['oid'] <= 0) {
header('Location: index.php');
}
$orderId = (int)$_GET['oid'];
// get ordered items
$sql = "SELECT pd_name, pd_price, od_qty
FROM tbl_order_item oi, tbl_product p
WHERE oi.pd_id = p.pd_id and oi.od_id = $orderId
ORDER BY od_id ASC";
$result = dbQuery($sql);
$orderedItem = array();
while ($row = dbFetchAssoc($result)) {
$orderedItem[] = $row;
}
// get order information
$sql = "SELECT od_date, od_last_update, od_status, od_shipping_first_name, od_shipping_last_name, od_shipping_address1,
od_shipping_address2, od_shipping_phone, od_shipping_state, od_shipping_city, od_shipping_postal_code, od_shipping_cost,
od_payment_first_name, od_payment_last_name, od_payment_address1, od_payment_address2, od_payment_phone,
od_payment_state, od_payment_city , od_payment_postal_code,
od_memo
FROM tbl_order
WHERE od_id = $orderId";
$result = dbQuery($sql);
extract(dbFetchAssoc($result));
$orderStatus = array('New', 'Paid', 'Shipped', 'Completed', 'Cancelled');
$orderOption = '';
foreach ($orderStatus as $status) {
$orderOption .= "<option value=\"$status\"";
if ($status == $od_status) {
$orderOption .= " selected";
}
$orderOption .= ">$status</option>\r\n";
}
?>
<p> </p>
<form action="" method="get" name="frmOrder" id="frmOrder">
<table width="550" border="0" align="center" cellpadding="5" cellspacing="1" class="detailTable">
<tr>
<td colspan="2" align="center" id="infoTableHeader">Order Detail</td>
</tr>
<tr>
<td width="150" class="label">Order Number</td>
<td class="content"><?php echo $orderId; ?></td>
</tr>
<tr>
<td width="150" class="label">Order Date</td>
<td class="content"><?php echo $od_date; ?></td>
</tr>
<tr>
<td width="150" class="label">Last Update</td>
<td class="content"><?php echo $od_last_update; ?></td>
</tr>
<tr>
<td class="label">Status</td>
<td class="content"> <select name="cboOrderStatus" id="cboOrderStatus" class="box">
<?php echo $orderOption; ?> </select> <input name="btnModify" type="button" id="btnModify" value="Modify Status" class="boxbutton" onClick="modifyOrderStatus(<?php echo $orderId; ?>);"></td>
</tr>
</table>
</form>
<p> </p>
<table width="550" border="0" align="center" cellpadding="5" cellspacing="1" class="detailTable">
<tr id="infoTableHeader">
<td colspan="3">Ordered Item</td>
</tr>
<tr align="center" class="label">
<td>Item</td>
<td>Unit Price</td>
<td>Total</td>
</tr>
<?php
$numItem = count($orderedItem);
$subTotal = 0;
for ($i = 0; $i < $numItem; $i++) {
extract($orderedItem[$i]);
$subTotal += $pd_price * $od_qty;
?>
<tr class="content">
<td><?php echo "$od_qty X $pd_name"; ?></td>
<td align="right"><?php echo displayAmount($pd_price); ?></td>
<td align="right"><?php echo displayAmount($od_qty * $pd_price); ?></td>
</tr>
<?php
}
?>
<tr class="content">
<td colspan="2" align="right">Sub-total</td>
<td align="right"><?php echo displayAmount($subTotal); ?></td>
</tr>
<tr class="content">
<td colspan="2" align="right">Shipping</td>
<td align="right"><?php echo displayAmount($od_shipping_cost); ?></td>
</tr>
<tr class="content">
<td colspan="2" align="right">Total</td>
<td align="right"><?php echo displayAmount($od_shipping_cost + $subTotal); ?></td>
</tr>
</table>
<p> </p>
<table width="550" border="0" align="center" cellpadding="5" cellspacing="1" class="detailTable">
<tr id="infoTableHeader">
<td colspan="2">Shipping Information</td>
</tr>
<tr>
<td width="150" class="label">First Name</td>
<td class="content"><?php echo $od_shipping_first_name; ?> </td>
</tr>
<tr>
<td width="150" class="label">Last Name</td>
<td class="content"><?php echo $od_shipping_last_name; ?> </td>
</tr>
<tr>
<td width="150" class="label">Address1</td>
<td class="content"><?php echo $od_shipping_address1; ?> </td>
</tr>
<tr>
<td width="150" class="label">Address2</td>
<td class="content"><?php echo $od_shipping_address2; ?> </td>
</tr>
<tr>
<td width="150" class="label">Phone Number</td>
<td class="content"><?php echo $od_shipping_phone; ?> </td>
</tr>
<tr>
<td width="150" class="label">Province / State</td>
<td class="content"><?php echo $od_shipping_state; ?> </td>
</tr>
<tr>
<td width="150" class="label">City</td>
<td class="content"><?php echo $od_shipping_city; ?> </td>
</tr>
<tr>
<td width="150" class="label">Postal Code</td>
<td class="content"><?php echo $od_shipping_postal_code; ?> </td>
</tr>
</table>
<p> </p>
<table width="550" border="0" align="center" cellpadding="5" cellspacing="1" class="detailTable">
<tr id="infoTableHeader">
<td colspan="2">Payment Information</td>
</tr>
<tr>
<td width="150" class="label">First Name</td>
<td class="content"><?php echo $od_payment_first_name; ?> </td>
</tr>
<tr>
<td width="150" class="label">Last Name</td>
<td class="content"><?php echo $od_payment_last_name; ?> </td>
</tr>
<tr>
<td width="150" class="label">Address1</td>
<td class="content"><?php echo $od_payment_address1; ?> </td>
</tr>
<tr>
<td width="150" class="label">Address2</td>
<td class="content"><?php echo $od_payment_address2; ?> </td>
</tr>
<tr>
<td width="150" class="label">Phone Number</td>
<td class="content"><?php echo $od_payment_phone; ?> </td>
</tr>
<tr>
<td width="150" class="label">Province / State</td>
<td class="content"><?php echo $od_payment_state; ?> </td>
</tr>
<tr>
<td width="150" class="label">City</td>
<td class="content"><?php echo $od_payment_city; ?> </td>
</tr>
<tr>
<td width="150" class="label">Postal Code</td>
<td class="content"><?php echo $od_payment_postal_code; ?> </td>
</tr>
</table>
<p> </p>
<table width="550" border="0" align="center" cellpadding="5" cellspacing="1" class="detailTable">
<tr id="infoTableHeader">
<td colspan="2">Buyer's Memo</td>
</tr>
<tr>
<td colspan="2" class="label"><?php echo nl2br($od_memo); ?> </td>
</tr>
</table>
<p> </p>
<p align="center">
<input name="btnBack" type="button" id="btnBack" value="Back" class="boxbutton" onClick="window.history.back();">
</p>
<p> </p>
<p> </p>
and index.php
Code: Select all
<?php
require_once '../../library/config.php';
require_once '../library/functions.php';
$_SESSION['login_return_url'] = $_SERVER['REQUEST_URI'];
checkUser();
$view = (isset($_GET['view']) && $_GET['view'] != '') ? $_GET['view'] : '';
switch ($view) {
case 'list' :
$content = 'list.php';
$pageTitle = 'Éalú MediSpa Thearpy Control Panel - View Orders';
break;
case 'detail' :
$content = 'detail.php';
$pageTitle = 'Éalú MediSpa Thearpy Control Panel - Order Detail';
break;
case 'modify' :
modifyStatus();
//$content = 'modify.php';
//$pageTitle = 'Éalú MediSpa Thearpy Control Panel - Modify Orders';
break;
default :
$content = 'list.php';
$pageTitle = 'Éalú MediSpa Thearpy Control Panel - View Orders';
}
$script = array('order.js');
require_once '../include/template.php';
?>
Will this info help?