Zenax
Active Member
- Messages
- 1,377
- Reaction score
- 4
- Points
- 38
PHP:
<?Php
// including the db connection script
require_once("connect_db.php");
// declaring the variables
$username = $_POST['username'];
$password = $_POST['password'];
$passrept = $_POST['passrept'];
// stripping HTML tags from the info entered
$_POST['username'] = strip_tags($_POST['username']);
$_POST['password'] = strip_tags($_POST['password']);
$_POST['passrept'] = strip_tags($_POST['passrept']);
// Checking a username is not already taken
$SQL = "SELECT * FROM users WHERE users = $username";
$result = mysql_query($SQL);
$num_rows = mysql_num_rows($result)or die(mysql_error());
if ($num_rows > 0) {
$errorMessage = "Username already taken";
}
else {
}
// encrypt the password into md5
$_POST['password'] = md5($_POST['password']);
// inserting the data into the db
$insert = mysql_query("INSERT INTO users VALUES ('". $_POST['username'] ."', '". $_POST['password'] ."') ")
or die("Could not insert data because ".mysql_error());
echo ('Your account has been added!');
?>
Currently working on a PHP registration script for my CMS. I am needing to check if a username is taken, and the tutorials I have fount online seem to follow the route highlighted in bold.
Do help me out as that method does not work. Thanks for your help.