Anyone can view my PHP code? How to fix my data redundancy in my PHP to mysql? I dont wish to store the same data to my database. thankyou
<?php
$email = "";
$passwords = "";
$firstname = "";
$lastname = "";
$errors = array();
$db = mysqli_connect('localhost', 'root', '', 'wdt_assignment');
if (isset($_POST['email'])) {
$email = mysqli_real_escape_string($db, $_POST['email']);
$password = mysqli_real_escape_string($db, $_POST['password']);
$firstname = mysqli_real_escape_string($db, $_POST['firstname']);
$lastname = mysqli_real_escape_string($db, $_POST['lastname']);
if (empty($email)) { array_push($errors, "email is required"); }
if (empty($password)) { array_push($errors, "password is required"); }
if (empty($firstname)) { array_push($errors, "firstname is required"); }
if (empty($lastname)) { array_push($errors, "lastname is required"); }
}
$user_check_query = "SELECT * FROM customer WHERE email='$Email' OR password='$Password' LIMIT 1";
$result = mysqli_query($db, $user_check_query);
$user = mysqli_fetch_assoc($result);
if ($user) { // if user exists
if ($user['email'] === $Email) {
array_push($errors, "email already exists");
}
if ($user['password'] === $Password) {
array_push($errors, "password already exists");
}
}
if (count($errors) == 0) {
$query = "INSERT INTO customer (email, password, firstname, lastname)
VALUES('$email', '$password', '$firstname','$lastname')";
mysqli_query($db, $query);
$_SESSION['email'] = $email;
$_SESSION['success'] = "You are now logged in";
}
?>