<html>
<head>
<title>Authentication</title>
</head>
<body>
<b>REGISTER</b>
<br />
<a href="auth_login.php">Login</a><br />
<form method="post" action="auth_register_confirm.php">
USER ID: <input name="user_name" type="text" required /><br/>
PASSWORD: <input name="password" type="password" required /><br/>
Re-enter password: <input name="password2" type="password" required /><br/>
Name: <input name="name" type="text" required /><br/>
Email Address: <input name="email" type="email" /><br/>
<input type="submit" value="REGISTER" />
</form>
</body>
</html>
<?php
define ('DB_USER', 'root');
define ('DB_PASSWORD', '');
define ('DB_HOST', 'localhost');
define ('DB_NAME', 'BGdb');
// mysqli_connect function is used to connect to the database
$conn = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
?>
<?php
include("conn.php"); //connect to database
//Cleanup the input
$user_name=mysqli_escape_string($conn,$_POST['user_name']);
$password=mysqli_escape_string($conn, $_POST['password']);
$password2=mysqli_escape_string($conn, $_POST['password2']);
$email=mysqli_escape_string($conn, $_POST['email']);
$name=mysqli_escape_string($conn, $_POST['name']);
//encode the password
$password_encode=md5($password);
// validate to check if the password and renter password is same
if($password !== $password2){
$msg="Sorry your PASSWORD is not
the same as the RE-ENTER PASSWORD, please
<a href=\"javascript:history.back()\">Try Again!</a>";
}else{
//check if the username or password is already use
$sql = "SELECT * FROM user WHERE user_name = '$user_name'
OR password = '$password_encode'";
$sql_query = mysqli_query($conn, $sql) or
die(mysqli_error($conn));
//if exist....
if (mysqli_num_rows($sql_query) == 1) {
$msg="Sorry a user already use the USER ID or PASSWORD you intend using,
please change the login ID and <a href=\"javascript:history.back()\">Try Again!</a>";
}else{
//if not existing.... then register
$sql="INSERT INTO user VALUES ('','$user_name',
'$password_encode','$name', '$email')";
mysqli_query($conn, $sql) or die(mysqli_error($conn));
$msg="Thank you!
your registration was successfull.
<a href=\"auth_login.php\">LOGIN HERE!</a>";
}
}
?>
<html>
<head>
<title>Authentication</title>
</head>
<body>
<b>REGISTER</b>
<br/>
<?php
if (isset($msg)){
print $msg;
}
?>
</body>
</html>
//encode the password
$password_encode=md5($password);
// validate to check if the password and renter password
// is same
if($password !== $password2){
.....
//check if the username or password is already use
$sql = "SELECT * FROM user WHERE user_name = '$user_name' OR password = '$password_encode'";
$sql_query = mysql_query($sql, $conn) or die(mysql_error());
....
/if use....
if (mysql_num_rows($sql_query) >= 1) {
No Comment yet!