Jump to content

[SOLVED] MySQL- Detect Values


SJames

Recommended Posts

I am trying to make a system that detects wherther an entry has been made in the database containing a certain value.

 

More accurately, the system checks the database of usernames to see if the username the user entered in the sign up page has been used. If not, it allows the name to be used, if so, it does not allow it to be used.

 

The database stores the information in the cells: username, password, and userID (an auto-incrementing cell)

The database is called usernames.

 

What I am asking for is the code I would use to do the username check. Basically:

 

if (username has been used) {

    don't allow user to sign up, and present an error message

} else {

    allow user to sign up, and complete the registration process

}

Link to comment
Share on other sites

Simply query the database beforehand. Assuming the username the user typed is contained within $_POST['uname']....

 

<?php

  // connect to db.

  if ($result = mysql_query("SELECT uname FROM users WHERE uname = '{$_POST['uname']}'")) {
    if (mysql_num_rows($result)) {
      // username already exists.
    } else {
      // do INSERT query for new user.
    }
  }

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.