Hello,
I'm trying to modify an existing php page by adding a submit button, to allow the user to change the unit cost of a product in the inventory. I can get the product informations from the database, but nothing happens when I press the submit button. The fist submit button in the code allows to retrieve the product information by entering the serial number, this one works.
Many thanks for your help!
Yanoli
Here is php code:
<?php
/* $Revision: 1.6 $ */
$PageSecurity = 3;
include('includes/session.inc');
$title = _('Serial Item Research');
include('includes/header.inc');
//validate the submissions
if (isset($_POST['serialno'])) {
$SN = trim($_POST['serialno']);
} elseif(isset($_GET['serialno'])) {
$SN = trim($_GET['serialno']);
} else {
$SN = '';
}
$SN = $SN;
if (isset($_POST['submitcost'])) {
$sql = "UPDATE purchorderdetails SET unitprice='" . $_POST['unitcost'] . "'";
}
?>
<div class="centre">
<br>
<form name=SNRESEARCH method=post action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php echo _('Serial Number') ?>: <input ID="serialno" name="serialno" size=21 maxlength=20 VALUE="<?php echo $SN; ?>">
<input type=submit name=submit>
</form>
<form name=unitcost method=post action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php echo _('New unit cost') ?>: <input ID="submitcost" name="submitcost" size=21 maxlength=20 VALUE="">
<input type=submit name=submitcost>
</form>
<SCRIPT>
document.getElementById('serialno').focus();
</SCRIPT>
<?php
if ($SN!='') {
//the point here is to allow a semi fuzzy search, but still keep someone from killing the db server
if (strstr($SN,'%')){
while(strstr($SN,'%%')) {
$SN = str_replace('%%','%',$SN);
}
if (strlen($SN) < 11){
$SN = str_replace('%','',$SN);
prnMsg('You can not use LIKE with short numbers. It has been removed.','warn');
}
}
$SQL = "SELECT stockserialitems.stockid,
stockserialitems.serialno AS serialno,
stockmaster.description,
stockserialmoves.ordernossm,
purchorderdetails.unitprice AS unitcost,
stockcategory.categorydescription,
stockmaster.categoryid
FROM stockserialitems,
stockmaster,
stockserialmoves,
purchorderdetails,
stockcategory
WHERE stockserialitems.stockid=stockmaster.stockid
AND stockserialitems.serialno=stockserialmoves.serialno
AND stockserialmoves.ordernossm=purchorderdetails.orderno
AND stockserialmoves.stockid=purchorderdetails.itemcode
AND stockmaster.categoryid=stockcategory.categoryid
AND stockserialitems.serialno like '$SN'
ORDER BY stockmaster.description";
$result = DB_query($SQL,$db);
$myrow = DB_fetch_array($result);
$_POST['stockid'] = $myrow['stockid'];
$_POST['serialno'] = $myrow['serialno'];
$_POST['description'] = $myrow['description'];
$_POST['unitcost'] = $myrow['unitcost'];
echo '<table>';
echo '<tr><td>' . _('Stock ID') . ':</td><td><input type="text" name="stockid" VALUE="' . $_POST['stockid'] . '" size=42 maxlength=40></td></tr>';
echo '<tr><td>' . _('Serial Number') . ':</td><td><input type="text" name="serialno" VALUE="' . $_POST['serialno'] . '" size=42 maxlength=40></td></tr>';
echo '<tr><td>' . _('Description') . ':</td><td><input type="text" name="description" VALUE="' . $_POST['description'] . '" size=42 maxlength=40></td></tr>';
echo '<tr><td>' . _('Unit Cost') . ':</td><td><input type="text" name="unitcost" VALUE="' . $_POST['unitcost'] . '" size=42 maxlength=40></td></tr>';
echo '</table>';
}//END OF POST IS SET
echo '</div>';
include('includes/footer.inc');
?>