<?php
$db = new mysqli('localhost','root','','felhasznalok');
if (isset($_POST['submit'])) {
$errors = array();
$true = true;
if (empty($_POST['username'])) {
$true = false;
array_push($errors, "A felhasználónév üres!");
}
if (empty($_POST['password'])) {
$true = false;
array_push($errors, "A jelszó üres!");
}
if (empty($_POST['password_2'])) {
$true = false;
array_push($errors, "A jelszó megerősítés üres!");
}
if (!($_POST['password']==$_POST['password_2'])
$true = false;
array_push($errors, "A jelszavak nem egyeznek!");
}
if ($true) {
$username = mysqli_real_escape_string($db, $_POST['username']);
$password = mysqli_real_escape_string($db, $_POST['password']);
$password = md5($password);
$sql = "INSERT INTO users(username, password, Date) VALUES('$
username', '$password' ,NOW())";
$db->query($sql);
session_start();
$_SESSION['username'] = $username;
header('location: home.php');
}
}
$db->close();
?>
<html>
<head>
</head>
<body>
<form action="register.php" method="POST"/>
username<input type="text" name="username"/>
password<input type="password" name="password"/>
re_password<input type="password" name="password_2"/>
<input value="Regisztráció" type="submit" name="submit"/>
</form>
<?php
if (!empty($errors)) {
foreach ($errors as $key) {
echo $key. "<br/>";
}
}
?>
</body>
</html>