Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Include function - Submit data Example

    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 :

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

    Cheers, Will.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    New Coder
    Join Date
    Jul 2005
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    PHP Code:
    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(!$resulterror_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');
    }


  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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:
    PHP Code:
    $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 `ausapapersummarySET ' . $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?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    New Coder
    Join Date
    Jul 2005
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the advice.
    I've actually reverted that piece of code back to the way I had it.

    which is :
    PHP Code:
    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) ?

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You *shouldn't* need to create arguments for this.
    Heres how to test that though:
    PHP Code:
    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 Code:
    <?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.
    Last edited by Fou-Lu; 09-18-2005 at 05:02 PM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #7
    New Coder
    Join Date
    Jul 2005
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    )
    Last edited by facets; 09-18-2005 at 05:14 PM.

  • #8
    New Coder
    Join Date
    Jul 2005
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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');
    }
    }
    ?>

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    whoa whoa, slow down sport. Run this at the top of your page:
    PHP Code:
    $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?

    Edit:
    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
    Last edited by Fou-Lu; 09-18-2005 at 05:31 PM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #10
    New Coder
    Join Date
    Jul 2005
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #11
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #12
    New Coder
    Join Date
    Jul 2005
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #13
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #14
    New Coder
    Join Date
    Jul 2005
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    PHP Code:
    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 :

    PHP Code:
    <input type="submit\" class=\"btn\" value=\"Update\" name=\"submit\"> 
    any other suggestions
    Last edited by facets; 09-20-2005 at 03:48 PM.

  • #15
    New Coder
    Join Date
    Jul 2005
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    just discovered that if I change the default in my swutch case to to the editSummary function it saves my data to the db.

    PHP Code:
    $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?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •