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.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Update DB using other than submit form

    Hi There,

    Perhaps my other question was too 'much' to start with.
    So i'll break it down and ask the main question.

    How do I submit to a DB with out using the 'submit' function in a form.
    I think I need to do this as my code is being included from a functions page.
    So i'm guessing the variable isn't being passed.

    Also, the other issue is that once I do hit submit it reloads the index page rather the edit.php page. Obviously index.php is my default in the switch case.

    Any suggestions?

    PHP Code:

    // Set varibale for switch action 
    $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:
            
    showMenu();
            break;
       } 

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Databases by no means require the use of submit, that simply provides us with a way to create the variables, perhaps one of the easiest to use and control.
    You can update the database through the standard UPDATE query (OR INSERT if not existant), and your variables can be hardcoded, passed through post/get, etc.
    Now, I'm not certain on your problem exactly, but if its relative to using POST then the issue lies in your _GET. Change it to _REQUEST instead, that will cover either the POST or GET, where POST overrides GET. That will allow you to use this either with a POST form, or through the url.

    Functions can be generally tricky as well, you have to be careful of your scope. Functions can only see two things -> themselves and superglobals. They cannot see anything else by default. Any variables that need to be include which are not relatives of the superglobals need to be added with a global $var command. This scope is something that traps a lot of people, especially new people. This is also the reason why I always comment on using _* vars instead of HTTP_*_VARS, as HTTP_*_VARS are not autoglobal and need to be globalized within a function use. I myself initialize the HTTP_*_VARS as a part of the superglobals for olderversions of php, and therefore need to globalize these variables for use with older versions within the array:
    global $_POST for instance. Normally $_POST is global, but it may not be with the older versions as my code.

    And lastly, the switch() function does not require that your default case be broken. Actually, its not the default, its the last case of switch doesn't need a break in it. I don't *think* this causes problems, but I'm not certain -> I've never used a break with my last case

    Is this of any help to you?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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