SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question creating a restriction on number of users

    im trying to create a script for admin, that only allows three admin users be registered, if any more people try to register than 3 they will be told to contact the database administator. ive included my code below, but it doesnt wrk becase i can still add more than 3 admin users to the db.
    PHP Code:
       $query "select * from admin";

        
    $results mysql_query($query)
         or die(
    mysql_error());
        
    $count mysql_num_rows($results);
        
    //extract($row);
      
        
    if ( $count ){
    echo 
    'Their is a limit to the number of administrators that can be registered. Please contact you database administrator.';
    die();
        }
    $query "INSERT INTO user SET " 
    "username='" $_POST['username'] . "', " 
    "first_name='" $_POST['first_name'] . "', " 
    "last_name='" $_POST['last_name'] . "', " 
    "password='" .md5($_POST['password']) . "', " 
    "address1='" $_POST['address1'] . "', " 
    "address2='" $_POST['address2'] . "', " 
    "city='" $_POST['city'] . "', " 
    "postcode='" $_POST['postcode'] . "'";
     echo 
    $query;
          
    $result mysql_query($query
            or die(
    mysql_error());
          
    $_SESSION['username'] = $_POST['username']; 

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Your code allows 4 admin users, as that's the first number greater than 3.

    PHP Code:
    if ($count >= 3

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope it doesnt wrk, it still can add more

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    echo $count and see what it says, and have a look at your admin table... there's too little to this code for it to not be working correctly

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ive sorted it now, thanks i made a mistake in another part


Bookmarks

Posting Permissions

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