web_AI-3/registration.php

46 lines
1.5 KiB
PHP
Raw Normal View History

2017-02-05 14:49:57 +01:00
<!DOCTYPE html>
<html>
<head>
2017-02-05 14:54:30 +01:00
<meta charset="utf-8">
<title>Registration</title>
<link rel="stylesheet" href="css/loginstyle.css" />
2017-02-05 14:49:57 +01:00
</head>
2017-02-05 14:54:30 +01:00
2017-02-05 14:49:57 +01:00
<body>
<?php
require('db.php');
// If form submitted, insert values into the database.
2017-02-05 14:54:30 +01:00
if (isset($_REQUEST['username'])) {
// removes backslashes
2017-02-05 14:52:25 +01:00
$username = stripslashes($_REQUEST['username']);
2017-02-05 14:54:30 +01:00
//escapes special characters in a string
2017-02-05 14:52:25 +01:00
$username = mysqli_real_escape_string($con,$username);
$email = stripslashes($_REQUEST['email']);
$email = mysqli_real_escape_string($con,$email);
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($con,$password);
$trn_date = date("Y-m-d H:i:s");
2017-02-05 14:54:30 +01:00
$query = "INSERT into `users` (username, password, email, trn_date)
VALUES ('$username', '".md5($password)."',
'$email', '$trn_date')";
2017-02-05 14:49:57 +01:00
$result = mysqli_query($con,$query);
2017-02-05 14:54:30 +01:00
if ($result) {
2017-02-05 14:49:57 +01:00
echo "<div class='form'>
2017-02-05 14:54:30 +01:00
<h3>You are registered successfully.</h3>
<br/>Click here to <a href='login.php'>Login</a></div>";
2017-02-05 14:49:57 +01:00
}
2017-02-05 14:54:30 +01:00
} else {
2017-02-05 14:49:57 +01:00
?>
<div class="form">
<h1>Registration</h1>
<form name="registration" action="" method="post">
<input type="text" name="username" placeholder="Username" required />
<input type="email" name="email" placeholder="Email" required />
<input type="password" name="password" placeholder="Password" required />
<input type="submit" name="submit" value="Register" />
</form>
</div>
<?php } ?>
</body>
</html>