Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Junior Member
    Join Date
    Apr 2005
    Location
    Scotland
    Posts
    3
    Member #
    9659
    Hey..
    Someone please help me, I've been at this for ages.

    All I want to do is... when a user is registering, I want to check that the username they choose doesn't already exist in the database.

    I've tried so many different examples, and they all end up in error saying

    Fatal error: Call to undefined function query() in .....

    Someone please help me....arghhh....

    Here's ma code...

    <html>

    <head>
    <title>LCP Scotland Carpool Entry Results</title>
    </head>

    <body>
    <p><img src="scotlandflag.bmp"> <img src="Picture1.emf" width="250" height="70"></p>
    <h1>Carpool Entry Results</h1>
    <form action="registration.php" method="POST">
    PHP Code:
    <?PHP



    $title
    =$_POST['title'];
    $firstname=$_POST['firstname'];
    $surname=$_POST['surname'];
    $town=$_POST['town'];
    $postcode=$_POST['postcode'];
    $email=$_POST['email'];
    $username=$_POST['username'];
    $password=$_POST['password'];
    $confpassword=$_POST['confpassword'];
    $carowner=$_POST['carowner'];
    $institution=$_POST['institution'];
    $comments=$_POST['comments'];
    $security=0;


    $pass "true";


    //Check user has supplied a first name
    if ($firstname == ""
    {
    echo 
    "<p>You need to supply a first name</p>";
    $pass "false";


    //Check user has supplied a surname
    if ($surname == ""
    {
    echo 
    "<p>You need to supply a surname</P>";
    $pass "false";
    }
    //Check user has supplied a town
    if ($town == ""
    {
    echo 
    "<p>You need to supply a town</p>";
    $pass "false";
    }
    //Check user has supplied a postcode
    if ($postcode == ""
    {
    echo 
    "<p>You need to supply a postcode</p>";
    $pass "false";
    }

    //Check user has supplied an email address
    if ($email == ""
    {
    echo 
    "<p>You need to supply an email address</p>";
    $pass "false";
    }


    //Email Validation
    function checkemail($email){ 
    return 
    preg_match("/^[^\s()<>@,;:\"\/\[\]?=]+@\w[\w-]*(\.\w[\w-]*)*\.[a-z]{2,}$/i",$email); 
            }
    if((!
    $email) OR (!checkemail($email))) 
    {
    echo 
    "<p>You did not enter a valid e-mail address<p>"
    $pass "false";
    }

    //Check user has supplied a username
    if ($username == ""
    {
    echo 
    "<p>You need to supply a username</p>";
    $pass "false";
    }

    //Check user has supplied a password
    if ($password == ""
    {
    echo 
    "<p>You need to supply a password</p>";
    $pass "false";
    }

    //Check password length is ok
    if (strlen($password)<6)
    {
    echo 
    "<p>Your password must be at least 6 characters long<p>";
    $pass "false";
    }

    //Check user has confirmed password
    if ($confpassword == ""
    {
    echo 
    "<p>You need to confirm your password</p>";
    $pass "false";
    }


    //Check users password corresponds to confirmation password
    if ($password != $confpassword)
    {
    echo 
    "<p>Your passwords do not match. Please type more carefully</p>";
    $pass "false";
    }


    //Check user has supplied the days attended
    if ($comments == ""
    {
    echo 
    "<p>You need to supply the days you attend</p>";
    $pass "false";
    }



    if (
    $pass == "true") {
    //run magic quotes and enter details to database

    if (!get_magic_quotes_gpc())
    {

    $title=addslashes($title);
    $firstname=addslashes($firstname);
    $surname=addslashes($surname);
    $town=addslashes($town);
    $postcode=addslashes($postcode);
    $email=addslashes($email);
    $username=addslashes($username);
    $password=addslashes($password);
    $confirm_password=addslashes($confirm_password);
    $carowner=addslashes($carowner);
    $institution=addslashes($institution);
    $comments=addslashes($comments);
    }

    $db_conn = new mysqli('localhost''root''button12','lcp');
      if (
    mysqli_connect_errno()) {
       echo 
    'Connection to database failed:'.mysqli_connect_error();
       exit();
      }
    //-----------------
    // lets check to see if the username already exists
    $checkuser query("SELECT username FROM members WHERE username='$username'"); 
    $username_exist mysql_num_rows($checkuser);
    if(
    $username_exist 0){
    echo 
    "I'm sorry but the username you specified has already been taken. Please pick another one.";
    unset(
    $username);
    include 
    'registration.php';
    exit();


    //__________________

    $query "insert into members values 
    ('"
    .$title."','".$firstname."','".$surname."','".$town."','".$postcode."','".$email."','".$username."','".$password."','".$carowner."','".$institution."', '".$comments."','".$security."')";
    $result $db_conn->query($query);
    echo 
    'Your details have been added to the carpool database!';
    $db_conn->close();
     echo 
    '<p><a href="index.php"><strong><font face="Times New Roman, Times, serif">Login</font></strong></a></p>';}
     
     
    // Let's mail the user! 
        
    $subject "Your Membership at LCP Scotland!"
        
    $message "Dear $firstname $surname
        Thank you for registering at our website, http://lcp-scotland.no-ip.org! 
         
        You are two steps away from logging in and accessing our exclusive members area. 
         
        To activate your membership, please click here: 
        http://lcp-scotland.no-ip.org/activate.php?id=
    $username&code=$password 
         
        Once you activate your membership, you will be able to login with the following 
        information: 
        Username: 
    $username 
        Password: 
    $password
         
        Thanks! 
        The Webmaster 
         
        This is an automated response, please do not reply!"

         
        
    mail($email$subject$message
            
    "From: LCP Scotland Webmaster<admin@LCP-Scotland.no-ip.org>\n 
            X-Mailer: PHP/" 
    phpversion()); 
       echo 
    'Your membership information has been mailed to your email address! 
       Please check it and follow the directions!'


    //stop point
    ?>

    </body>
    </html>

  2.  

  3. #2
    Senior Member mossoi's Avatar
    Join Date
    Apr 2003
    Location
    Englandshire, United Kingdomsville y'all!
    Posts
    1,111
    Member #
    1206
    Liked
    1 times
    Try changing this line:
    Code:
    $checkuser = query("SELECT username FROM members WHERE username='$username'");
    To this:
    Code:
    $checkuser = mysql_query("SELECT username FROM members WHERE username='$username'");

  4. #3
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    As you're using PHP 5.x, that will be:
    PHP Code:
    $checkuser $db_conn->query("SELECT username FROM members WHERE username='$username'")or die($db_conn->error);

    //or procedural
    $checkuser mysqli_query($db_conn"SELECT username FROM members WHERE username='$username'")or die(mysqli_error($db_conn)); 
    You can also set a 'UNIQUE' index on the 'username' column, as that will reject non-unique usernames.
    S. Rosland

  5. #4
    Junior Member
    Join Date
    Dec 2004
    Posts
    9
    Member #
    8527
    best thing to do is just use an email address as a login.... Save all the hasstle of usernames.

  6. #5
    Senior Member mossoi's Avatar
    Join Date
    Apr 2003
    Location
    Englandshire, United Kingdomsville y'all!
    Posts
    1,111
    Member #
    1206
    Liked
    1 times
    As you're using PHP 5.x, that will be:
    Oops - didn't spot that it was 5.x.

  7. #6
    Junior Member
    Join Date
    Apr 2005
    Location
    Scotland
    Posts
    3
    Member #
    9659
    Right, I changed it to this...

    // lets check to see if the username already exists
    $checkuser = mysqli_query($db_conn, "SELECT username FROM members WHERE username='$username'")or die(mysqli_error($db_conn));
    $username_exist = mysql_num_rows($checkuser);
    if($username_exist > 0){
    echo "I'm sorry but the username you specified has already been taken. Please pick another one.";
    unset($username);
    include 'registration.php';
    exit();
    }


    but now I get...
    Fatal error: Call to undefined function mysql_num_rows() in ...

  8. #7
    Junior Member
    Join Date
    Apr 2005
    Location
    Scotland
    Posts
    3
    Member #
    9659
    AH-HA....

    got it working...
    changed this ....
    $username_exist = mysql_num_rows($checkuser);

    to this

    $username_exist = mysqli_num_rows($checkuser);

    thanks for all your help peeps!!

    redmouse
    x

  9. #8
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    137 times
    Quote Originally Posted by Markdamo
    best thing to do is just use an email address as a login.... Save all the hasstle of usernames.
    BAD IDEA. If user names are displayed on the site at all, spam bots will skim the email addresses.
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com


Remove Ads

Posting Permissions

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

Search tags for this page

html form check if username exist

,

php form check username doesnt exist

Click on a term to search for related topics.
All times are GMT -6. The time now is 06:23 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com