...

View Full Version : Function : Submit issues



facets
09-21-2005, 02:09 AM
Hello All,

I'm having some trouble with the following two functions.
The submit button doesn't seem to execute the updateSummary() function.
I've tried many options to no avail.
Can anyone shed some light ?

Ta, Will



<?
include_once "../includes/functions.inc.php";
include "../includes/common_db.inc";
include("template.inc");

//global $action;

$link_id = db_connect($db_materials);

// Set varibale for switch action
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
$submit = isset($_REQUEST['submit']) ? $_REQUEST['submit'] : '';
$Update = isset($_REQUEST['Update']) ? $_REQUEST['Update'] : '';

switch($action) {

case "editSASummary":
editSASummary();
break;
case "viewStockSpec":
fnViewFaceStockSpec();
break;
case "addSAStockSummary" :
addSAStockSummary();
break;
case "Update" :
updateSummary();
break;
case "submit" :
updateSummary();
break;
default:
showMenu();
}

echo 'GET <pre>';
var_dump($_GET);
var_dump($_POST);
echo 'POST </pre>';

function updateSummary() {

$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';

$summaryId = isset($_REQUEST['summaryId']) ? $_REQUEST['summaryId'] : '';
$paperCategoryId = isset($_REQUEST['paperCategoryId'] ) ? $_REQUEST['paperCategoryId'] : '';
$colloPaperName = isset($_REQUEST['colloPaperName'] ) ? $_REQUEST['colloPaperName'] : '';
$manufacturerName = isset($_REQUEST['manufacturerName']) ? $_REQUEST['manufacturerName'] : '';

// updateSummary Database with new fields if changed
$query = "UPDATE ausapapersummary SET

paperCategoryId='$paperCategoryId', colloPaperName='$colloPaperName', manufacturerName='$manufacturerName' ,cpl='$cpl', stockId='$stockId' WHERE summaryId = '$summaryId'";

$result = mysql_query($query);

if (mysql_affected_rows() == 1) {
updated();
$tmpl->set_block('page', 'footer');
$tmpl->pparse('out', 'footer');
}

else {

error_log(mysql_error());
echo "<P>Something went wrong.</P>";
}

}

function editSASummary() {

$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
$summaryId = isset($_REQUEST['summaryId']) ? $_REQUEST['summaryId'] : '';

// 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'];


// 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";
}


echo "<table class=\"sorttable\">";
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\" name=\"submit\" class=\"btn\" value=\"Update\"></td></tr>";
echo "</table></form><br>";

}
?>

Badman3k
09-21-2005, 10:44 AM
That'll be because you only switching on the action variable and as the submit is being stored in the $submit variable you're never actually getting the value submit in the $action.

However from what you've posted I can't tell whether or not you have a (hidden) field in your form called action that has the value "submit" in it. If you do then it should go throught the switch and find the 'submit' case and thus run the function updateSummary().

Looking at what you already have I'd take it that you don't always want to submit so having the hidden field is not going to help, so what I'd suggest is changing:
$submit = isset($_REQUEST['submit']) ? $_REQUEST['submit'] : '';
to:
$action = isset($_REQUEST['submit]) ? "submit" : $action;

This will assign submit to the $action if the submit button was pressed, otherwise it will leave the action as it was.

Not sure whether or not this is what you want to do, but I hope it helps.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum