Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 3 123 LastLast
Results 1 to 10 of 23
  1. #1
    Join Date
    Apr 2006
    Location
    Leamington Spa
    Posts
    1,375
    Tokens
    72

    Latest Awards:

    Default Check a whole database for something?

    When my users fill in this form on our site their IP gets put in the database along with the other data....
    How could I make it check to see if their IP is already in the database?

    EDIT:
    Atm I've got:
    PHP Code:
    $check mysql_query("SELECT `ip` FROM `entries` WHERE `ip` = '$ip' ;");

    if(isset(
    $check)){ die('You cannot enter more than once!'); } 
    Any help appreciated.
    Last edited by lolwut; 17-11-2007 at 12:49 PM.
    i've been here for over 8 years and i don't know why

  2. #2
    Join Date
    Jun 2007
    Location
    England
    Posts
    495
    Tokens
    0

    Default

    ohhhhhh i know this :S but forgotten... Give me a min

    Edited by opensourcehost (Forum Super Moderator): Please do not post pointlessly.
    Last edited by Mr.OSH; 17-11-2007 at 01:09 PM.

  3. #3
    Join Date
    Jul 2005
    Location
    -
    Posts
    2,995
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Waterfall View Post
    When my users fill in this form on our site their IP gets put in the database along with the other data....
    How could I make it check to see if their IP is already in the database?

    EDIT:
    Atm I've got:
    PHP Code:
    $check mysql_query("SELECT `ip` FROM `entries` WHERE `ip` = '$ip' ;");

    if(isset(
    $check)){ die('You cannot enter more than once!'); } 
    Any help appreciated.
    PHP Code:
    $fetch7 mysql_query("SELECT `ip` FROM `entries` WHERE `ip` = '$ip'")
    or die(
    mysql_error());  
        
    $fetch8 mysql_num_rows($fetch7);
    if (
    $fetch8 == 0) {
    //the ip doesnt exist }
    else {
    //the ip exists 


  4. #4
    Join Date
    Jan 2007
    Location
    Canada eh?
    Posts
    766
    Tokens
    75

    Default

    Try a php look:

    PSEUDO CODE:
    PHP Code:
    <?php
    while($dbs get_mysql_table_list('from_db');){
         
    //Do your check here
         
    if(entry found){
              
    $found 'yup';
         }
    }
    if(
    $found == "yup"){
         
    //It exists!
    }else{
         /
    Sorrynothing...
    }
    ?>
    Note that is pseudo code - therefore it wont actually parse or work, it is just meant to explain the logic behing what I'm suggesting.

  5. #5
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    PHP Code:
    if( mysql_num_rows($sql) > )
    {
    // Error
    } else
    {
    // Stuff


  6. #6
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
    <?php
    include "config.php"// includes config file

    $check_i mysql_query("SELECT ip FROM entries WHERE ip='$ip'");
    $check_n mysql_num_rows($check_i);
    if (
    $check_n == "" || $check_n == "0")
    {
        echo 
    "You cannot enter more then once!";
        exit;
    }
    ?>

  7. #7
    Join Date
    Sep 2006
    Location
    Hobart, Australia
    Posts
    593
    Tokens
    0

    Default

    Quote Originally Posted by Dentafrice, View Post
    PHP Code:
    <?php
    include "config.php"// includes config file

    $check_i mysql_query("SELECT ip FROM entries WHERE ip='$ip'");
    $check_n mysql_num_rows($check_i);
    if (
    $check_n == "" || $check_n == "0")
    {
        echo 
    "You cannot enter more then once!";
        exit;
    }
    ?>

    mysql_num_rows() returns an integar, and only an integar. There's no need to check for empty strings, or to treat the 0 like a string, by enclosing it with quotes.

  8. #8
    Join Date
    May 2007
    Location
    Nebo, NC, USA
    Posts
    2,517
    Tokens
    0

    Latest Awards:

    Default

    It doesn't matter, thats the way I do it.

  9. #9
    Join Date
    Sep 2006
    Location
    Hobart, Australia
    Posts
    593
    Tokens
    0

    Default

    Quote Originally Posted by Dentafrice, View Post
    It doesn't matter, thats the way I do it.
    Well, it's a waste of server resources, time, and most importantly, waste the energy your fingers have to go to typing it in

    PHP Code:
    if(mysql_num_rows($query) > 0) {

         
    // Rows were returned

    }

    else {

         
    // No rows returned (0)


    That's all you need to do to check for rows returned
    Last edited by Beau; 17-11-2007 at 08:54 PM.

  10. #10
    Join Date
    Nov 2006
    Location
    Narrich
    Posts
    5,687
    Tokens
    0
    Habbo
    Jamesy...

    Latest Awards:

    Default

    haha that's like the script you told me last night.

    You are good!
    Ex-janitor. Might pop in from time to time, otherwise you can grab all my information from http://jamesy.me.uk/

Page 1 of 3 123 LastLast

Posting Permissions

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