...

View Full Version : Include function - Submit data Example



facets
09-18-2005, 01:44 PM
Does anyone have a good example that I could follow on how to update a database with the following conditions ?

Function included via include file.

Main index has 'switch' function for editting like :


switch($action) {
case "editSASummary":
editSASummary();
break;
case "viewSpec":
fnViewFaceStockSpec();
break;
default:
showMenu();
break;
}

Cheers, Will.

Fou-Lu
09-18-2005, 03:13 PM
Hey Facets,
You don't have any conditions for me to work with. All I have is the $action to see, and the functions to execute code. Unfortunatly, I'm not certain what it is you need to update, which fields, which conditions, and what to update. Can you be a little more clear?

facets
09-18-2005, 03:23 PM
Here's the code i'm trying to use to update my DB with
It works Ok when in the form page itself, so I knwo it's 'kida' working.
Ideally, i'm sure this can be done. My OO skills are very limited and i'm still getting my head around functions. So please excuse the average coding.



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');
}
}

Fou-Lu
09-18-2005, 03:44 PM
You may run into trouble with the mixing of the _GET and _POST variables, but thats not the trouble in this case.
The trouble I see offhand is this:
$fields = array(

$summaryId => 'summaryId',
$paperCategoryId => 'paperCategoryId',
$manufacturerName => 'manufacturerName',
$cpl => 'cpl',
$stockId => 'stockId',
$adhesiveId => 'adhesiveId',
$linerId => 'linerId',
$supplierId => 'supplierId',
);

This will give you troubles, as it suggest the values of $summaryId, etc, etc, to be existant, which they are not. Drop the variables:


$fields = array(

'summaryId',
'paperCategoryId',
'manufacturerName',
'cpl',
'stockId',
'adhesiveId',
'linerId',
'supplierId',
);
// Blah blah blah:
foreach ($fields AS $field)
{
if (!empty($_POST[$field]))
{
$query_fields .= '`' . $field . '` = '' . mysql_real_escape_string($_POST[$field]) . ', ';
}
}
$query_fields = substr($query_fields, 0, strlen($query_fields) - 2);
if (!empty($query_fields))
{
$query = 'UPDATE `ausapapersummary` SET ' . $query_fields . ' WHERE summaryID = '' . mysql_real_escape_string($summaryID) . ''; // Type cast it maybe?
}



Give that a shot, just run the code first with an echo before preforming the mysql_query to it. Any luck with that?

facets
09-18-2005, 03:53 PM
Thanks for the advice.
I've actually reverted that piece of code back to the way I had it.

which is :

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', suitabilityFoil='$suitabilityFoil', suitabilityYellowLight='$suitabilityYellowLight', suitabilityLabel='$suitabilityLabel', suitabilityOpacity='$suitabilityOpacity', suitabilityBronze='$suitabilityBronze', suitabilityScreen='$suitabilityScreen', suitabilityIceBucket='$suitabilityIceBucket' 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>";
}

} else {


But the same problems occurs.
For the time being, i've put this code back on a single page but would love to merge this with the functions code. Obviously I do not have the function command/title on the 'same page' just calling the code directly. It may be something to do with that.

Should I need to bring all the variable into the function code ala :
function editSummary($summaryId, $papaerCategroyId etc etc) ?

Fou-Lu
09-18-2005, 04:00 PM
You *shouldn't* need to create arguments for this.
Heres how to test that though:


function editSASummary() {
echo '<pre>';
print_r($_GET);
echo '</pre>';
}

Try that out, calling your function from your main page. I guess I should double check as well, you are including this somehow correct? As in, these functions are in say functions.php, and you are using this on main.php to use them right:


<?php
include_once('./functions.php');
?>

for instance?
Anyway, if your function returns values from your url query string (just add some random stuff, do=whatever&test=this&this=that), to see if it appears to be passing correctly.

Oh yeah, btw, you need to change specifically your $_GET['summaryID'] to either $_POST or $_REQUEST. I'm blind, and missed that you are sending this only via POST from what I can see. Try to alter that one as well, part of the problem may be that $summaryID is null. You don't want it to preform the query if this value is ever empty.

facets
09-18-2005, 04:04 PM
Sorry , maybe I didn't say, displays the function OK (ie, pulls the related summaryId data from the DB and populates the DB) I can then make text changes when I hit update, it fails.

What I haven't tried though is using the function on thesame page like you suggest. Will try that now.

The summaryId is being passed through OK. (When the page loads)
And is being passed via POST on the UPDATE :

Array
(
)
Array
(
[summaryId] => 210
[commented] => set
[paperCategoryId] => 1
[colloPaperName] => Killer White 90 S2500
[manufacturerName] => Fasson Killer White 90/S2500/BG42HD BL
[cpl] => KILLWHS2500
[stockId] => 702
[adhesiveId] => 25
[linerId] => 42
[supplierId] => 4
[availability] => Immediate availability
[features] => Open weaved paper.
[limitations] => Full adhesion is critical when bottling
[productExamples] => Some info 2 4
[suitabilityFoil] => 3
[suitabilityYellowLight] => 3
[suitabilityLabel] => 4
[suitabilityOpacity] => 1
[suitabilityBronze] => 5
[suitabilityScreen] => 3
[suitabilityIceBucket] => 2
[submit] => Update
)

facets
09-18-2005, 04:06 PM
Just checked! it works fine from with a function on the same page.
So here's the code..

OH, Thanks again for your valuable help!!!!

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

// Open connection to database //
$link_id = db_connect($db_materials);

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


$username = $_SERVER["REMOTE_USER"];
$result1 = mysql_query("SELECT * FROM users WHERE userName='$username'");
$result2 = mysql_query("SELECT * FROM admins WHERE userName='$username'");

$userPass = mysql_fetch_array($result1);
$adminPass = mysql_fetch_array($result2);

if ($adminPass) {

$id = $adminPass['id'];
$name = $adminPass['name'];
$userName = $adminPass['userName'];
$email = $adminPass['email'];

}

else if ($userPass) {

$id = $userPass['id'];
$name = $userPass['fullName'];
$username = $userPass['userName'];
$email = $userPass['email'];

}

else { error(); }

// Switch case for 'View' popups
switch($action) {

case "editStockSpec": fnViewFaceStockSpec(); break;
case "editAdhesiveSpec": fnViewAdhesiveSpec(); break;
case "editLinerSpec": fnViewLinerSpec(); break;
default: editSASummary(); break;
}

// Pull in summaryId //

// Edit Summary Function

function editSASummary() {

$username = $_SERVER["REMOTE_USER"];
$result1 = mysql_query("SELECT * FROM users WHERE userName='$username'");
$result2 = mysql_query("SELECT * FROM admins WHERE userName='$username'");

$userPass = mysql_fetch_array($result1);
$adminPass = mysql_fetch_array($result2);

if ($adminPass) {

$id = $adminPass['id'];
$name = $adminPass['name'];
$userName = $adminPass['userName'];
$email = $adminPass['email'];

}

else if ($userPass) {

$id = $userPass['id'];
$fullName = $userPass['fullName'];
$name = $userPass['userName'];
$email = $userPass['email'];

}

else { error();
}

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

// Header and Title //
$tmpl = new Template(".", "keep");
$tmpl->set_file('page', "page.html");
$tmpl->set_var('TITLE', "Edit - Australian Self Adhesive Paper Summary");
$tmpl->set_block('page', 'header');
$tmpl->pparse('out', 'header');

//

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', suitabilityFoil='$suitabilityFoil', suitabilityYellowLight='$suitabilityYellowLight', suitabilityLabel='$suitabilityLabel', suitabilityOpacity='$suitabilityOpacity', suitabilityBronze='$suitabilityBronze', suitabilityScreen='$suitabilityScreen', suitabilityIceBucket='$suitabilityIceBucket' 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>";
}

} 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'];
$suitabilityFoil = $query_data['suitabilityFoil'];
$suitabilityYellowLight = $query_data['suitabilityYellowLight'];
$suitabilityLabel = $query_data['suitabilityLabel'];
$suitabilityOpacity = $query_data['suitabilityOpacity'];
$suitabilityBronze = $query_data['suitabilityBronze'];
$suitabilityScreen = $query_data['suitabilityScreen'];
$suitabilityIceBucket = $query_data['suitabilityIceBucket'];

// 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>";
echo "<div class=subTitle>Suitability</div>\n\n";
echo "<table class=\"sorttable\">";

$displayAvailability=array('Foil','Yellow Light','Neck Labels','Opacity','Bronze','Screen','Ice Bucket');
$displayAvailabilityTitles = array(fnSuitabilityFoil($suitabilityFoil),fnSuitabilityYellowLight($suitabilityYellowLight),fnSuitab ilityLabel($suitabilityLabel), fnSuitabilityOpacity($suitabilityOpacity),fnSuitabilityBronze($suitabilityBronze),fnSuitabilityScree n($suitabilityScreen),fnSuitabilityIceBucket($suitabilityIceBucket));

for($x = 0; $x<count($displayAvailability); $x++) {
echo "<tr><td width=\"200px\" colspan=\"2\" valign=\"top\">".$displayAvailability[$x]."</td>\n\n";
echo "<td width=\"200px\" colspan=\"4\" valign=\"top\">".$displayAvailabilityTitles[$x]."</td></tr>\n\n";
}
echo "</table>";

// 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');
}
}
?>

Fou-Lu
09-18-2005, 04:22 PM
whoa whoa, slow down sport. Run this at the top of your page:


$register_globals = (bool)ini_get('register_globals');
(empty($register_globals) OR $register_globals === FALSE) ? $register_globals = 'off' : $register_globals = 'on';

echo 'Register Globals are currently <b>' . $register_globals . '</b><br />';

Does it say globals are on or off?


One more thing, rename and refer to your included files (.inc) as .inc.php. You want that .php at the end, as by default servers will not parse .inc files and therefore return the request as plain/text. Meaning, if you hold configuration information within these files, you are pretty much requesting a user to take over your database - which would be bad :)

facets
09-19-2005, 02:52 AM
Register Globals are currently off
As they should be. Right? For security etc.

And i've amended the .inc to reflect .inc.php.
Thanks for that advice.

Fou-Lu
09-19-2005, 05:13 AM
Register globals can be on or off, it doesn't really matter so long as your program with security in mind, it would be fine. Put error_reporting(E_ALL) at the top of your page, if you have any notices you need to fix them up, those are uninitialized variables which can be assigned using a request method should your globals be on.
You got this up and running then yeah?

facets
09-19-2005, 06:18 AM
Yup errors E_ALL is in my php config file.
So i guess i don;t need them on the page.
I tail -f the errors_log too :)

Fou-Lu
09-19-2005, 02:54 PM
Thats correct, if its in a file you include, that will cover the entire routine. Once you get it active an in use on a server, I'd recommend using error_reporting(0), just in case something happens, you don't want to display to other users what your code is doing or what it looks like. Personally, I always use E_ALL & ~E_NOTICE once its complete, this way prior to my globals stripping code if the user attempts to set a variable of their own (not just a new value, but an entire variable), it won't display the errors for them.
Glad you got it all working though. Let me know of any more troubles, I'd be glad to help you out.

facets
09-20-2005, 02:18 PM
Hi There.. Unfortunately the issue isn't resolved. But the my php.ini file is set correctly :) I'll try to explain the process a little clearer..

The function works well if it's on the the editpage.php but if I move it to the function.inc.php it cease to work. No errors, after submit it reloads the same page without the edited data. I've run out of ideas on where to look.

I don'd think the following code is being exectuted when I hit submit.


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', suitabilityFoil='$suitabilityFoil', suitabilityYellowLight='$suitabilityYellowLight', suitabilityLabel='$suitabilityLabel', suitabilityOpacity='$suitabilityOpacity', suitabilityBronze='$suitabilityBronze', suitabilityScreen='$suitabilityScreen', suitabilityIceBucket='$suitabilityIceBucket' 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>";
}

Here's the submit code :


<input type=\"submit\" class=\"btn\" value=\"Update\" name=\"submit\">

any other suggestions

facets
09-20-2005, 03:13 PM
just discovered that if I change the default in my swutch case to to the editSummary function it saves my data to the db.



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

switch($action) {

case "editStockSpec": fnViewFaceStockSpec(); break;
case "editAdhesiveSpec": fnViewAdhesiveSpec(); break;
case "editLinerSpec": fnViewLinerSpec(); break;
case "editSASummary": editSASummary(); break;
case "viewStockSpec": fnViewFaceStockSpec(); break;
case "viewAdhesiveSpec": fnViewAdhesiveSpec(); break;
case "viewLinerSpec": fnViewLinerSpec(); break;
case "viewAddFaceStock": fnAddFaceStock(); break;
case "addAdhesive": fnAddAdhesive(); break;
case "addLiner": fnAddLiner(); break;
case "addFs": fnCreateFs(); break;
case "addFaceStock": viewAddFaceStock(); break;
case "addSAStockSummary" : addSAStockSummary(); break;
default: editSASummary();
}


I really want default to be showMenu()

Why would this be happening?

Fou-Lu
09-20-2005, 03:28 PM
$action isn't set.
Change this:


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

to this:


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

I'm thinking that you are initially sending it from a form with post method, but could be a get method. $_REQUEST will access either.
Also, another heads up, I don't *think* it should cause you problems on 4.3x versions of php, but you may want to include your database connection file before that of your function files. This shouldn't be a problem as the functions are not accessed until after both have loaded, but should you attempt to access the functions prior to the database connections, it will result in errors.
Give that a shot.

facets
09-20-2005, 03:38 PM
that isn't it either :) I'll keep trying different thing. it must be something simple.. surely!

Fou-Lu
09-21-2005, 04:46 AM
Hmm, I never noticed this before, and I suppose this could create problems for you:

$link_id = db_connect($db_materials);

Now, I'm thinking that since your function is embedded within another page, the use of your connection is fine within a function as a call to the mysql has been done. Personally, I didn't think this could be done at all.
Try adding:


global $link_id;

to you function call. See if that does it. Geez, then that doesn't matter what the action is set as either, which I'm still trying to figure out.
Tell you what, why not send me these files, as well as your database .sql dump, I'll check the entire thing out.

facets
09-21-2005, 05:12 AM
Thank you very much for your assistance.
I finally got it working by splitting my code into smaller functions.

Now i'm working optimising the code.

thanks again, you've been most helpful!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum