Here the edit code which is contained in my functions.inc file.
The editSASummary function is being called from a search page which loads the data from the DB and populates the dropdowns and textboxes.
Now I wish to edit them and update the db. When i hit the submit/update button the page reloads the default switch case and the DB isn't updated. No errors etc!
This code was originally on a page by itself, not in a function and it worked fine. But it's really like to know how to do this 'cross' page variable passing etc.
TIA..
Code: Select all
function editSASummary() {
$summaryId = isset($_GET['summaryId']) ? $_GET['summaryId'] : '';
if(isset($_POST['submit']))
{
posted();
// Setup Array of Statements and Fields
$fields = array(
$summaryId => 'summaryId',
$paperCategoryId => 'paperCategoryId',
$manufacturerName => 'manufacturerName',
$cpl => 'cpl',
$stockId => 'stockId',
$adhesiveId => 'adhesiveId',
$linerId => 'linerId',
$supplierId => 'supplierId',
);
// Create SQL WHERE statement for searching. Check for variable validity.
foreach ($fields as $statement => $field) {
if (!empty($_POST[$statement])) {
$query = "UPDATE ausapapersummary SET ".$field." = ".mysql_real_escape_string($_POST[$statement])." WHERE summaryId = '$summaryId'";
}
}
// SQL Testing result
echo $query;
// Execute SQL Query
$result = mysql_query($query);
// Error SQL Query
if(!$result) error_message(sql_error());
} else {
// Query DB for summaryId //
$sql_query = mysql_query("SELECT * FROM ausapapersummary WHERE summaryId = $summaryId");
$query_data = mysql_fetch_array($sql_query);
// Assign Variables //
$paperCategoryId = $query_data['paperCategoryId'];
$colloPaperName = $query_data['colloPaperName'];
$manufacturerName = $query_data['manufacturerName'];
$cpl = $query_data['cpl'];
$stockId = $query_data['stockId'];
$adhesiveId = $query_data['adhesiveId'];
$linerId = $query_data['linerId'];
$supplierId = $query_data['supplierId'];
$availability = $query_data['availability'];
$features = $query_data['features'];
$limitations = $query_data['limitations'];
$productExamples = $query_data['productExamples'];
// Set Up Form and Table
echo "<form name=\"editSASummary\" action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"summaryId\" value=$summaryId>";
echo "<input type='hidden' name='commented' value='set'>\n";
echo "<table class=\"sorttable\">\n";
// Bring in paperCategoryId
$first=array('Paper Category');
$firstTitles = array(fnPaperCategory($paperCategoryId));
for($x = 0; $x<count($first); $x++) {
echo "<tr><td width=\"200px\" colspan=\"2\" valign=\"top\">".$first[$x]."</td>\n";
echo "<td width=\"200px\" colspan=\"4\">$firstTitles[$x]</td></tr>\n\n";
}
$second = array('Collo Paper Name','Manufactured Name','Computer Loopup Prefix');
$secondTitles = array('colloPaperName','manufacturerName','cpl');
$secondValues = array($colloPaperName,$manufacturerName,$cpl);
for($x = 0; $x<count($second); $x++) {
echo "<tr><td width=\"200px\" colspan=\"2\" valign=\"top\">".$second[$x]."</td>\n";
echo "<td width=\"200px\" colspan=\"4\"><input class=\"text\" type=\"text\" name=\"".$secondTitles[$x]."\" size=\"50\" maxlength=\"100\" value=\"".$secondValues[$x]."\"></td></tr>\n\n";
}
// Bring in StockId , AdhesvieID, LinerId and allow views and edits.
$displayStock = array('Face Stock','Adhesive','Liner');
$displayStockTitles = array(fnListFaceStock($stockId),fnListAdhesive($adhesiveId),fnListLiner($linerId));
$displayButton = array(fnViewStock($stockId),fnViewAdhesive($adhesiveId),fnViewLiner($linerId));
for($x = 0; $x<count($displayStock); $x++) {
echo "<tr><td width=\"200px\" colspan=\"2\" valign=\"top\">".$displayStock[$x]."</td>\n\n";
echo "<td width=\"200px\" colspan=\"2\">$displayStockTitles[$x]</td>\n";
echo "<td width=50px>$displayButton[$x]</td></tr>\n\n";
}
// Bring in supplierId
$displaySupply = array('Supplier');
$displaySupplyTitles = array(fnListSupplier($supplierId));
for($x = 0; $x<count($displaySupply); $x++) {
echo "<tr><td width=\"200px\" colspan=\"2\" valign=\"top\">".$displaySupply[$x]."</td>\n";
echo "<td width=\"200px\" colspan=\"4\">$displaySupplyTitles[$x]</td></tr>\n\n";
}
$displayAvailability=array('Availability','Features','Limitations','Product Examples');
$displayAvailabilityTitles = array('availability', 'features', 'limitations', 'productExamples');
$displayAvailabilityValues = array($availability,$features,$limitations,$productExamples);
for($x = 0; $x<count($displayAvailability); $x++) {
echo "<tr><td width=\"200px\" colspan=\"2\" valign=\"top\">".$displayAvailability[$x]."</td>\n";
echo "<td width=\"200px\" colspan=\"4\"><input class=\"text\" type=\"text\" name=\"".$displayAvailabilityTitles[$x]."\" SIZE=\"20\" value=\"".$displayAvailabilityValues[$x]."\"></td></tr>\n\n";
}
echo "</table><br>";
// Button table
echo "<table class=\"sorttable\">";
if ($adminPass) {
echo "<tr><td><br><input class=\"btnEdit\" type=\"button\" value=\"Print Summary\" onclick=\"window.open ('print.php?action=print&summaryId=$summaryId','_self')\">";
echo "<td><br><input type=\"reset\" class=\"btn\" value=\"Reset Summary\"></td>";
//echo "<td><br><input type=\"submit\" class=\"btn\" value=\"Update\" name=\"submit\"></td>";
echo "<td><br><input type=\"button\" class=\"btn\" value=\"Update\" onclick=\"window.open ('index.php?action=editSASummary&summaryId=$summaryId','_self')\"></td>";
}
echo "</table></form><br>";
$tmpl->set_block('page', 'footer');
$tmpl->pparse('out', 'footer');
}
}