You might like
1. Shop card
I. Introduction how to set up and run the whole existing source code
II. Original Source Code with PHP
Video part 1: Create a database and register for an account
PHP Register
<?php
$conn = mysqli_connect('localhost', 'root', '', 'burgershop');
$username = $_POST['username'];
$password = $_POST['password'];
$repassword = $_POST['repassword'];
if(isset($_POST['register'])){
if($username && $password && $repassword){
if($password == $repassword){
$sql = "select username from register where username = '$username'";
$query = mysqli_query($conn, $sql);
if(mysqli_fetch_row($query) == 1){
echo "Account existed";
}else{
$sql = "insert into register(username, password) values('$username', '$password')";
$query = mysqli_query($conn, $sql);
if($query){
// echo "Account created";
header('location: ./index.php');
}else{
echo "Fail to create account";
}
}
}else{
// echo "try again";
header('location: ./index.php');
}
}
}
?>
Video part 2: Log in to our account with a registered username and password
PHP Login
<?php
$conn = mysqli_connect('localhost', 'root','', 'burgershop');
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM register WHERE username ='$username'";
$query= mysqli_query($conn, $sql);
$row = mysqli_fetch_array($query);
if(mysqli_num_rows($query) == 1){
if($row['password'] == $password){
header("location: ./burgershop.html");
}else{
echo "Please recheck your password again";
}
}else{
echo "Invalid information, please try again";
}
?>
Video part 3: Reset a new password
Source code
PHP Reset password
<?php
$conn = mysqli_connect('localhost', 'root', '', 'burgershop');
$username = $_POST['username'];
$newpassword = $_POST['newpassword'];
if(isset($_POST['resetpassword'])){
$sql = "UPDATE register SET password='$newpassword' WHERE username='$username'";
$query = mysqli_query($conn, $sql);
header('location: ./index.php');
}
?>