Hi guys,
I have a couple of php files that perform various tasks.
I will use fields in my system and provide code as well
I need help as follows:
My database contains the fields Category and Brand
I need to make some changes on a a number of brands in a Category
ie the Category is "LADIES" and has about 700 brands
I make a search of a Category, it lists the results.
I make my change of the first brand, and will want it to redirect to the results page without losing the search criteria.
For now I redirect it to the index page.
How do I achieve this?
Is there a script I can put after my posting script to redirect the page without losing the search criteria?
Or how do I re-organise my files?
The files following;
The index page
-
<?php
-
require_once '../../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 = 'Fragrance Lounge - Stock panel';
-
break;
-
-
case 'add' :
-
$content = 'add.php';
-
$pageTitle = 'Fragrance Lounge - Add Stock ';
-
break;
-
-
case 'modify' :
-
$content = 'modify.php';
-
$pageTitle = 'Fragrance Lounge - Modify Stock';
-
break;
-
-
case 'detail' :
-
$content = 'detail.php';
-
$pageTitle = 'Fragrance Lounge - Showing Stock Details';
-
break;
-
-
case 'showbybrand' :
-
$content = 'showbybrand.php';
-
$pageTitle = 'Fragrance Lounge - Showing Stock By Brand';
-
break;
-
-
case 'showbycategory' :
-
$content = 'showbycategory.php';
-
$pageTitle = 'Fragrance Lounge - Showing Stock By Category';
-
break;
-
-
case 'showbysearch' :
-
$content = 'showbysearch.php';
-
$pageTitle = 'Fragrance Lounge - Showing Stock By Searching';
-
break;
-
-
case 'stocksheet' :
-
$content = 'printsheet.php';
-
$pageTitle = 'Fragrance Lounge - Printing stock sheet';
-
break;
-
-
case 'add' :
-
$content = 'add.php';
-
$pageTitle = 'Fragrance Lounge - Add Stock';
-
break;
-
-
default :
-
-
$content = 'list.php'; //the default page which holds the search form
-
$pageTitle = 'Fragrance Lounge - Stock panel';
-
}
-
-
$script = array('stock.js');
-
-
require_once '../include/template.php';
-
?>
-
The page with the search form
The page from where I make the change
-
<?php
-
if (!defined('WEB_ROOT')) {
-
exit;
-
}
-
-
if (isset($_GET['StockID']) && (int)$_GET['StockID'] > 0) {
-
$StockID = (int)$_GET['StockID'];
-
}
-
else
-
{
-
header('Location: index.php');
-
}
-
-
$errorMessage = (isset($_GET['cstock_error']) && $_GET['cstock_error'] != '') ? $_GET['cstock_error'] : ' ';
-
-
$sql = "SELECT * FROM fragrancestock WHERE StockID = $StockID";
-
$result = dbQuery($sql);
-
extract(dbFetchAssoc($result));
-
?>
-
<p class="errorMessage"><?php echo $errorMessage; ?></p>
-
<form action="processStock.php?action=modify" method="post" enctype="multipart/form-data" name="frmModifyStock" id="frmModifyStock">
-
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable">
-
<tr>
-
<td colspan="2" class="title_text">Add Stock</td>
-
</tr>
-
<tr>
-
<td class="label">Category</td>
-
<td width="755" class="content"><? echo $Category ?> </td>
-
</tr>
-
<tr>
-
<td class="label">Brand</td>
-
<td class="content"><? echo $Brand; ?></td>
-
</tr>
-
<tr>
-
<td class="label">Stock available</td>
-
<td class="content"><?php echo $Quantity; ?>
-
<input name="hidStockID" type="hidden" id="hidStockID" value="<?php echo $StockID; ?>" /></td>
-
</tr>
-
<tr>
-
<td class="label">Current Selling price </td>
-
<td class="content"><?php echo $SellingPrice; ?></td>
-
</tr>
-
<tr>
-
<td class="label">Add new stock quantity </td>
-
<td class="content"><input name="txtQuantity" type="text" value="" size="10" onkeyup="Modify_CheckQuantityField();" /></td>
-
</tr>
-
<tr>
-
<td width="245" class="label">New Selling price per brand </td>
-
<td class="content"><input name="txtSellingPrice" type="text" value="<?php echo $SellingPrice; ?>" size="20" onkeyup="Modify_CheckSellingPrice();" onclick="EmptyField();" />
-
(Change selling price here) </td>
-
</tr>
-
</table>
-
<input name="btnAddStock" type="submit" id="btnAddStock" value="Add Stock" onClick="return checkModifyNewStock();" class="button_image">
-
<input name="btnCancel" type="button" id="btnCancel" value="Cancel" onClick="window.history.back();" class="button_image">
-
</form>
-
The page that holds my database functions which includes the modify function after which I need the redirect to the search results page (ie the page before the modification page)
-
<?php
-
require_once '../../functions.php';
-
-
$action = isset($_GET['action']) ? $_GET['action'] : '';
-
-
switch ($action)
-
{
-
case 'add' :
-
addStock();
-
break;
-
-
case 'modify' :
-
modifyStock();
-
break;
-
-
case 'delete' :
-
deleteStock();
-
break;
-
-
case 'deletestockitem' :
-
deletestockItem();
-
break;
-
-
-
case 'deletestock' :
-
deletestockwithID();
-
break;
-
-
case 'deletestockcat' :
-
deletestockwithIDCat();
-
break;
-
default :
-
-
echo "<META HTTP-EQUIV=\"refresh\" content=\"; URL=index.php\"> ";
-
}
-
/*Add Stock*/
-
-
function addStock()
-
{
-
$Category = $_POST['sltCategory'];
-
$Brand = $_POST['sltBrand'];
-
$Quantity = $_POST['txtQuantity'];
-
$SP = $_POST['txtSellingPrice'];
-
-
// Check if the stock already exists
-
$sql1 = "SELECT Brand FROM fragrancestock WHERE Category = '$Category' AND Brand = '$Brand'";
-
$result = dbQuery($sql1);
-
-
if (dbNumRows($result) == 1)
-
{
-
echo '<script language="javascript">alert("This brand already exists in stock! Add a new one."); </script>;';
-
echo "<META HTTP-EQUIV=\"refresh\" content=\"; URL=index.php\"> ";
-
}
-
else
-
{
-
-
$sql = "INSERT INTO fragrancestock (Category, Brand, Quantity, SellingPrice, DateAddedStock)
-
VALUES ('$Category', '$Brand ', '$Quantity', '$SP', NOW())";
-
dbQuery($sql);
-
-
//$errorMessage = "Stock added successfully";
-
echo "<META HTTP-EQUIV=\"refresh\" content=\"; URL=index.php\"> ";
-
}
-
}
-
//Modify Stock.....This is the function that performs my modification to a brand
-
function modifyStock()
-
{
-
$StockID = (int)$_POST['hidStockID'];
-
$Quantity = $_POST['txtQuantity'];
-
$SP = $_POST['txtSellingPrice'];
-
-
$sql = "UPDATE fragrancestock SET Quantity = Quantity + '".$Quantity."',SellingPrice = '$SP', DateAddedStock = Now() WHERE StockID = '$StockID'";
-
dbQuery($sql);
-
-
//The redirect I have for now which takes the user back to the page with the search form, prompting them to search again....instead of returning to the search results so that the user just browses the pagination to go to the next brand to modify
-
-
echo "<META HTTP-EQUIV=\"refresh\" content=\"; URL=index.php\"> ";
-
-
function deleteStock()
-
{
-
if (isset($_GET['StockID']) && (int)$_GET['StockID'] > 0) {
-
$StockID = (int)$_GET['StockID'];
-
}
-
else
-
{
-
//header('Location: index.php');
-
echo "<META HTTP-EQUIV=\"refresh\" content=\"; URL=index.php\"> ";
-
}
-
-
$sql = "UPDATE fragrancestock SET Quantity = '0' WHERE StockID = $StockID";
-
dbQuery($sql);
-
//$errorMessage = "Stock deleted successfully";
-
echo "<META HTTP-EQUIV=\"refresh\" content=\"; URL=index.php\">";
-
}
-
-
function deletestockItem()
-
{
-
$Brand = $_POST['sltBrand'];
-
-
$sql2 = "DELETE FROM fragrancestock WHERE Brand = '$Brand'";
-
dbQuery($sql2);
-
-
echo "<META HTTP-EQUIV=\"refresh\" content=\"; URL=index.php\"> ";
-
}
-
-
function deletestockwithID()
-
{
-
if (isset($_GET['StockID']) && (int)$_GET['StockID'] > 0) {
-
$StockID = (int)$_GET['StockID'];
-
}
-
else
-
{
-
header('Location: index.php');
-
}
-
-
-
$sql = "DELETE FROM fragrancestock WHERE StockID = $StockID";
-
dbQuery($sql);
-
-
header('Location: index.php');
-
}
-
-
function deletestockwithIDCat()
-
{
-
if (isset($_GET['StockID']) && (int)$_GET['StockID'] > 0) {
-
$StockID = (int)$_GET['StockID'];
-
}
-
else
-
{
-
header('Location: index.php');
-
}
-
-
-
$sql = "DELETE FROM fragrancestock WHERE StockID = $StockID";
-
dbQuery($sql);
-
-
header('Location: index.php');
-
}
-
?>
-
There it is!
If you look at the modify function above, the redirect I have is to the search form page.
How do I redirect the user back to the results page so that the user does not have to search again, but instead continue to navigate the pagination and modify the next item?
The link to the results page on page 2 is:
http://localhost/cstock/admin/stock/...&search=LADIES