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
https://forums.phpfreaks.com/topic/67693-solved-mysql-detect-values/
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.
    }
  }

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.