Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2006
    Posts
    56

    Unanswered: Shouldn't I be using an Array in a comparison or what?

    This is driving me crazy. Don't know what I'm doing wrong. If anybody can help, it would be greatly appreciated.


    I have a function which grabs the form action (insert, update, delete, or other procedures) and checks whether or not that particular action is a valid one for that form.

    PHP Code:
    function grab_action($valid_actions) {

        
    $ActArray["action"]     = validate_input($_REQUEST["act"]);
        
    $ActArray["sid"]         = validate_input($_REQUEST["sid"]);
        
        
        
    // Turn the valid actions into an array.
        
    $valid_actions explode(", "$valid_actions);

        for (
    $i 0$i count($valid_actions); $i++) {
            if (
    $ActArray["action"] == valid_actions[$i]) { #This is Line 20 (Error Message)
                
    $ActArray["valid"] = true;
                break;
            }
            
            
    $ActArray["valid"] = false;
        }
        

        
    // If the action is valid, then proceed. else, error
        
    if ($ActArray["valid"]) {
            return 
    $ActArray;

        } else {
            
    $_SESSION["app_error"]             = 1;
            
    $_SESSION["app_error_descr"]     = "g6";
            
    header"Location: error.php" );

        }


    The other php page calls this function like this:

    PHP Code:
        // Sets the Valid $actions for this page
        
    $valid_actions "alt";
        
        
    // Grab the User $action. This will define the following variables: $action, $sid
        
    $Action grab_action($valid_actions);

        
    $user_id        validate_input$_SESSION["USR"]["sid"] );
        
    $Option_On_Order_Delivered validate_input$_REQUEST["Option_On_Order_Delivered"] );


    // Begin - Execute Query in a Command String ----------------------------------------------------------------------------------

        # Redefines $Default_Table's value
        
    $Default_Table "schema.table_name ";

        if (
    $Action["action"] == "alt") { // Update ------------------------------------------------------------------------------------
            
    $strCom "update " $Default_Table "set ";
            
    $strCom .=  "Option_On_Order_Delivered = '" $Option_On_Order_Delivered "' ";
            
    $strCom .=  "where user_id = '" $user_id "' ";
            
            
    # Execute
            
    fire_command($strCom); 
    The error message I get:

    Parse error: syntax error, unexpected '[' in C:\WebServer\Apache\htdocs\MyWebSite\includes\func tion_grab_action.php on line 20
    Am I missing something ??

    Any help appreciated.
    Thanks.

  2. #2
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    valid_actions is a variable...

    Line 20 should read :

    if ($ActArray["action"] == $valid_actions[$i]) {

    Notice the variable? You're attempting to use a constant called "valid_actions". Hence the error. I expect you to smack yourself on the forehead now

  3. #3
    Join Date
    Jul 2006
    Posts
    56
    hey hey I would never do that!! I usually just bang my head on my desk ...

    I can explain though ... hehe ... I'm migrating from ASP. Too lazy to just rewrite everything! I should be paying more attention to stuff like that. Guess I've been staring at this code for too long.

    Thank you very much.

  4. #4
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Ah no worries, the best of us make these mistakes. Bang head on desk, slap forehead, tear out hair, chew knuckles... all valid methods

Posting Permissions

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