How to make user register system with username checker?
1. Create table with 5 rows.
example: table name = users
CREATE TABLE `users` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`password` CHAR( 32 ) NOT NULL ,
`username` VARCHAR( 50 ) NOT NULL ,
`email` VARCHAR( 50 ) NOT NULL ,
`real_name` VARCHAR( 255 ) NOT NULL
) ENGINE = MYISAM
example register.php file:
<?php
if(isset($_POST['register'])){
$checkUsername_sql = "
SELECT
username
FROM
users
WHERE
username = '" . $_POST['username'] . "'
";
$checkUsername_res = mysql_query($checkUsername_sql);
$checkUsername = mysql_fetch_array($checkUsername_res);
$getUsername = $checkUsername['username'];
if(!$getUsername){
mysql_query("
INSERT INTO
users (username, password, email, real_name)
VALUES
('" . $_POST['username'] . "', '" . md5($_POST['password']) . "', '" . $_POST['email'] . "', '" . $_POST['real_name'] . "')
");
$result = 'Success';
}else{
$result = 'This username exist!';
}
}
?>
example register template file:
<html lang="en">
<head>
<title>Sample HTML File</title>
</head>
<body bgcolor="white">
<?
if(isset($_POST['register']) AND isset($result)){?>
echo $result;
}
?>
<div>
<form action="" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
E-mail: <input type="text" name="email" /> <br />
Real Name: <input type="text" name="real_name" /> <br />
<input type="submit" name="register" value="Register" />
</form>
</div>
</body>
</html>