This question already has an answer here:
im learning how to code etc.. i have copied this form from youtube, and i have changed it when i had some errors. my issue now is that after i try to register, the data from the form is not being saved.
could you guys point out what may be the issue
after i do all the steps and hit register it redirects me into the index.php (wich is ok, but the data is not stored). (database name etc was removed just in case for now).
<?php
//connect to database
$db = mysqli_connect("localhost", "", "", "");
if (isset($_POST['register_btn'])){
session_start();
$username = mysqli_real_escape_string($db,$_POST['username']);
$email = mysqli_real_escape_string($db,$_POST['email']);
$password = mysqli_real_escape_string($db,$_POST['password']);
$password2 = mysqli_real_escape_string($db,$_POST['password2']);
if ($password == $password2){
//create user
$password = md5($password); //hash password before storing for security
$sql = "INSERT INTO users(username, email, password) VALUES('$username', '$email', '$password')";
mysqli_query($db, $sql);
$_SESSION['message'] = "You are now registered";
$_SESSION['username'] = $username;
header("location: index.php"); // redirect to home page
}else {
echo $_SESSION['message'] = "The two passwords do not match";
}
}
?>
</div>