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

Thread: Array help!

  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Location
    Texas
    Posts
    472
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Array help!

    I have a MySQL database with member info in it, including ip address. But I can't get this to work:

    PHP Code:
    $query=mysql_query("select ipaddr from meminfo11");
    $iparray=mysql_fetch_array($query);
    $yourip=$_SERVER['REMOTE_ADDR'];
    if(
    in_array($yourip$iparray)) {
    die(
    "You're already a member.");

    But for some reason it doesn't work. What's wrong?
    If you're reading this, it may already be too late!

  • #2
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    mysql_fetch_array() only pulls one row of your result set per call. You'd be much better off just checking the ip directly against the database:

    PHP Code:
    $query "
     SELECT
      1
     FROM
      meminfo11
     WHERE
      ipaddr = '$yourip'"
    ;

    $result mysql_query($result) or die(mysql_error());

    if( 
    mysql_num_rows($result) == )
    {
       die(
    'you\'re already a member');



  •  

    Posting Permissions

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