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
    Jun 2012
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Checking if nickname exists in an array

    Hi all,

    I build a form on which people can enter their credentials on which they can acces the site.
    The only problem is that i want the people all have unique nicknames. So i questioned the DB to fill an array $nickname_bestaand with the following values: prof_id_bestaand and nickname_bestaand. To fill the array i use the compact() method like:

    PHP Code:
    $nickname_array[] = compact("prof_id_bestaand","nickname_bestaand"); 
    That's before the form. If i:
    PHP Code:
    print_r(array_values($nickname_array)) 
    it gives me all the values i have registered in the DB.

    Now i want to compare the entered nickname ($nickname) value to those in the array. So i call upon the in_array() like:
    PHP Code:
    if(in_array($nickname$nickname_array))
            {
            echo 
    "Uw gekozen nickname bestaat al, kies een andere!!";
            } 
    BUt everything it does, it doesn't compare the value of the nickname against the nickname_array.

    So anyone an idea how to resolve this problem, or where i make the mistake?

    Thanks in advance.

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    something like

    PHP Code:
    $nickname_array = Array("prof_id_bestaand" => "nickname_bestaand");
    foreach (
    $nickname_array as $key => $value){
        if (
    $nickname == $value){
            echo 
    "Uw gekozen nickname bestaat al, kies een andere!!";
        }



  •  

    Posting Permissions

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