Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // REGISTER USER
- if (isset($_POST['reg_user'])) {
- // receive all input values from the form
- $username = mysqli_real_escape_string($db, $_POST['username']);
- $password = mysqli_real_escape_string($db, $_POST['password']);
- $city = mysqli_real_escape_string($db, $_POST['city']);
- $state = mysqli_real_escape_string($db, $_POST['state']);
- $country = mysqli_real_escape_string($db, $_POST['country']);
- if (empty($username)) { array_push($errors, "Username is required"); }
- if (empty($password)) { array_push($errors, "Password is required"); }
- if (empty($city)) { array_push($errors, "City is required"); }
- if (empty($state)) { array_push($errors, "State is required"); }
- if (empty($country)) { array_push($errors, "Country is required"); }
- // register user
- if (count($errors) == 0) {
- $query = "INSERT INTO user (username, password, city, state, country)
- VALUES('$username', '$password', '$city','$state','$country')";
- mysqli_query($db, $query);
- $_SESSION['username'] = $username;
- $_SESSION['success'] = "You Are now Logged In!";
- header('location: index.php');
- }
- }
- // LOG USER IN
- if (isset($_POST['login_user'])) {
- $username = mysqli_real_escape_string($db, $_POST['username']);
- $password = mysqli_real_escape_string($db, $_POST['password']);
- if (empty($username)) {
- array_push($errors, "Username required");
- }
- if (empty($password)) {
- array_push($errors, "Password required");
- }
- if (count($errors) == 0) {
- $query = "SELECT * FROM userinfo WHERE username='$username' AND password='$password'";
- $results = mysqli_query($db, $query);
- if (mysqli_num_rows($results) == 1) {
- $_SESSION['username'] = $username;
- $_SESSION['success'] = "Welcome!";
- header('location: index.php');
- }else {
- array_push($errors, "Wrong username/password combination");
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement