Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- // variable declaration
- $username = "";
- $email = "";
- $errors = array();
- $_SESSION['success'] = "";
- $db = mysqli_connect('localhost', 'root', '', 'registration');
- // SIGNUP CUSTOMER
- if (isset($_POST['reg_user'])) {
- $username = mysqli_real_escape_string($db, $_POST['username']);
- $email = mysqli_real_escape_string($db, $_POST['email']);
- $password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
- $password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
- $telephone = mysqli_real_escape_string($db,$_POST['telephone']);
- $country = mysqli_real_escape_string($db,$_POST['country']);
- $state= mysqli_real_escape_string($db,$_POST['state']);
- if (empty($username)) { array_push($errors, "Username is required"); }
- if (empty($email)) { array_push($errors, "Email is required"); }
- if (empty($password_1)) { array_push($errors, "Password is required"); }
- if (empty($telephone)) { array_push($errors, "Telephone no. is required"); }
- if (empty($country)) { array_push($errors, "country is required"); }
- if (empty($state)) { array_push($errors, "state is required"); }
- if ($password_1 != $password_2) {
- array_push($errors, "The two passwords do not match");
- }
- if (count($errors) == 0) {
- $password = md5($password_1);
- $query = "INSERT INTO users (username, email, password, telephone,country,state)
- VALUES('$username', '$email', '$password','$telephone','$country','$state')";
- mysqli_query($db, $query);
- $_SESSION['username'] = $username;
- $_SESSION['success'] = "You are now logged in";
- header('location: index1.php');
- }
- }
- // ...
- // SIGNIN CUSTOMER
- 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 is required");
- }
- if (empty($password)) {
- array_push($errors, "Password is required");
- }
- if (count($errors) == 0) {
- $password = md5($password);
- $query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
- $results = mysqli_query($db, $query);
- if (mysqli_num_rows($results) == 1) {
- $_SESSION['username'] = $username;
- $_SESSION['success'] = "You are now logged in";
- header('location: index1.php');
- }else {
- array_push($errors, "Wrong username/password combination");
- }
- }
- }
- //SIGN UP DEALER
- if (isset($_POST['reg_dealer'])) {
- $username = mysqli_real_escape_string($db, $_POST['username']);
- $email = mysqli_real_escape_string($db, $_POST['email']);
- $password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
- $password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
- $account = mysqli_real_escape_string($db, $_POST['account']);
- $IFSC = mysqli_real_escape_string($db,$_POST['IFSC']);
- $target = mysqli_real_escape_string($db,$_POST['target']);
- $sales= mysqli_real_escape_string($db,$_POST['sales']);
- $date= mysqli_real_escape_string($db,$_POST['date']);
- $address= mysqli_real_escape_string($db,$_POST['address']);
- $telephone = mysqli_real_escape_string($db,$_POST['telephone']);
- $country = mysqli_real_escape_string($db,$_POST['country']);
- $state= mysqli_real_escape_string($db,$_POST['state']);
- if (empty($username)) { array_push($errors, "Username is required"); }
- if (empty($email)) { array_push($errors, "Email is required"); }
- if (empty($password_1)) { array_push($errors, "Password is required"); }
- if (empty($telephone)) { array_push($errors, "Telephone no. is required"); }
- if (empty($country)) { array_push($errors, "country is required"); }
- if (empty($state)) { array_push($errors, "state is required"); }
- if (empty($account)) { array_push($errors, "account is required"); }
- if (empty($IFSC)) { array_push($errors, "IFSC is required"); }
- if (empty($sales)) { array_push($errors, "sales is required"); }
- if (empty($date)) { array_push($errors, "date is required"); }
- if (empty($target)) { array_push($errors, "target is required"); }
- if (empty($address)) { array_push($errors, "address is required"); }
- if ($password_1 != $password_2) {
- array_push($errors, "The two passwords do not match");
- }
- if (count($errors) == 0) {
- $password = md5($password_1);
- $query = "INSERT INTO dealers (username, email, password, account,IFSC,target,sales, date,address,telephone,country,state)
- VALUES('$username', '$email', '$password','$account','$IFSC','$target','$sales','$date','$address',$telephone','$country','$state')";
- mysqli_query($db, $query);
- $_SESSION['username'] = $username;
- $_SESSION['success'] = "You are now logged in";
- header('location: index1.php');
- }
- }
- //SIGNIN DEALER
- if (isset($_POST['login_dealer'])) {
- $username = mysqli_real_escape_string($db, $_POST['username']);
- $password = mysqli_real_escape_string($db, $_POST['password']);
- if (empty($username)) {
- array_push($errors, "Username is required");
- }
- if (empty($password)) {
- array_push($errors, "Password is required");
- }
- if (count($errors) == 0) {
- $password = md5($password);
- $query = "SELECT * FROM dealers WHERE username='$username' AND password='$password'";
- $results = mysqli_query($db, $query);
- if (mysqli_num_rows($results) == 1) {
- $_SESSION['username'] = $username;
- $_SESSION['success'] = "You are now logged in";
- header('location: index1.php');
- }else {
- array_push($errors, "Wrong username/password combination");
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment