...

View Full Version : Function, Submit & Variable issues



facets
09-18-2005, 04:57 AM
Hello Coders,

I was hoping someone may be able to help with this problem.
I'm calling this function from a case statement, which is working fine.
it pulls in the required data etc. Problem is since i've this into a function and moved it from main edit page when I hit the update button the page reloads to the original 'default case statement' index.php and doesn't update the data into the db. I'm guessing it's a variable issue ?? perhaps with submit?
Also please feel free to pick holes in my code, i'm still learning here and seem to do things the long way.

TIA, Will.



function editSASummary() {

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

if (isset($_POST['submit'])) {

$summaryId = $_POST['summaryId'];
$paperCategoryId = $_POST['paperCategoryId'];
$colloPaperName = $_POST['colloPaperName'];
$manufacturerName = $_POST['manufacturerName'];
$cpl = $_POST['cpl'];
$stockId = $_POST['stockId'];
$adhesiveId = $_POST['adhesiveId'];
$linerId = $_POST['linerId'];
$supplierId = $_POST['supplierId'];
$availability = $_POST['availability'];
$features = $_POST['features'];
$limitations = $_POST['limitations'];
$productExamples = $_POST['productExamples'];
$suitabilityFoil = $_POST['suitabilityFoil'];
$suitabilityYellowLight = $_POST['suitabilityYellowLight'];
$suitabilityLabel = $_POST['suitabilityLabel'];
$suitabilityOpacity = $_POST['suitabilityOpacity'];
$suitabilityBronze = $_POST['suitabilityBronze'];
$suitabilityScreen = $_POST['suitabilityScreen'];
$suitabilityIceBucket = $_POST['suitabilityIceBucket'];

// Update Database with new fields if changed
$query = "UPDATE ausapapersummary SET paperCategoryId='$paperCategoryId', colloPaperName='$colloPaperName', manufacturerName='$manufacturerName' ,cpl='$cpl',
stockId='$stockId', adhesiveId='$adhesiveId', linerId='$linerId', supplierId='$supplierId', availability='$availability', features='$features',
limitations='$limitations', productExamples='$productExamples' WHERE summaryId = '$summaryId'";

$result = mysql_query($query);

if (mysql_affected_rows() == 1) {

echo "<P>Your comment has been updated.</P>";
}
else {
error_log(mysql_error());
echo "<P>Something went wrong.</P>";
}

}

// Set summaryId //
isset($_SESSION['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'];
$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 "<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\">";

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

raf
09-18-2005, 10:34 AM
i don't realy understand it.

if the problem is that your function isn't called, why do you then post your functions code? i'd then expect to see your code with the case-statement...

facets
09-18-2005, 11:02 AM
I'll try to explain.

The editSummary functions is called and loads the details related to the summaryId.
Then I edit a field and hit update
<input type=\"submit\" class=\"btn\" value=\"Update\" name=\"submit\">

The page reloads the index page and doesn't update the DB.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum