#1
  1. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,987
    Rep Power
    375

    Array key problem


    something weird is going on.... i have two arrays

    $_POST... this contains a key $_POST['interests']..
    I have another array $required_fields which contains (interests, first_name...)

    now what i am doing is:

    PHP Code:
    foreach ( $required_fields as $field ) {
            
    debug("2: -$field-",$flag); //this 
            
    debug($_POST[$field],$flag); //fails here
    ....... 
    it says " Undefined index: Interests in..... line....";

    i have done a dump of $_POST before this foreach

    PHP Code:
    Array ( [terms] => yes [first_name] => asd [last_name] => sssss [email] => test@test.com [title] => Mr [Interests] => test1 
    and the required field ( debug("2: -$field-",$flag); produces

    Code:
    *******DEBUG*****
    2: -Interests-
    *******END DEBUG*****
    so why would fail?

    Here is some more code:
    PHP Code:
    foreach ($_POST['terms'] as $key => $value){
                
    debug("-$key::: -$value-",$flag);
                
    $_POST[$key] = $value;
    }
        
    debug($_POST,$flag);
            
        
    $error = array();
        foreach ( 
    $required_fields as $field ) {
            
    debug("2: -$field-",$flag);
            
    debug($_POST[$field],$flag); 
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    make a var_dump() of both $_POST and $required_fields and post it here. I mean an actual var_dump(), not print_r(), echo or something like that.

    Inspecting the content of variables visually ("They look the same") isn't enough. You have to actually check the number of bytes to make sure you don't miss encoding issues or non-printable characters.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    I and i are not the same, check to make sure that isn't the problem. The debug output indicates that it isn't, but you said 'interests' instead of 'Interests' at the beginning of your post.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,987
    Rep Power
    375
    thanks for that.. interests/Interest was a typo from me.. sorry

    I have just var_dumped and found something strange...

    PHP Code:
    *******DEBUG*****
    string(25"interests"
    *******END DEBUG***** 
    but have been trying to figure it out how it is 25, normally when you view source, firefox tells you if there are extra lines or what not but in the view source i have it exactly as "interests" meaning no extra lines...
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7
    The name of the input box/drop-down or whatever that holds the interests from the submitted form... Is the name="" attribute of that interests, or Interests?

    <INPUT type="text" name="?????" />


    And can your run a print_r of your $required_fields and post it for us?
    Last edited by Triple_Nothing; February 22nd, 2013 at 11:55 AM.
  10. #6
  11. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    @Triple_Nothing: Did you read any of the above posts?

    @paulh1983: My Notepad++ says you have 16 "DLE" control characters after the actual word. How they got there I have no idea. Check the source of $required_fields. Either you've accidentally written those characters down, or your data got screwed up during transmission.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7
    @Jaques1: If you mean the questioning about the capital I, yes, but I am just clarifying we are speaking of and reference such in the same place. Most speach has been within the PHP script, and nothing of the html form, which is what truely defines this.

    What's odd, and why I want to be sure of this, is it seems that 'Interests' is the Only thing capitalized. Sorry to seem a bit anal here... :-/
  14. #8
  15. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    He already has posted a dump/echo of both $_POST and $required_fields. Both had a capital "I" (so obviously the input name is "Interests"). I guess he has changed it now to "interests" -- hopefully.

    But like I already said, there are a bunch of control characters after the actual word. So it's no wonder the string comparison fails.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo