mansi_singhal2

UserRegistration.php

Jul 24th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.19 KB | None | 0 0
  1. ######## Code for UserRegistration.php
  2.  
  3. <?php
  4.     $DB_HOST="localhost";//declaring server
  5.     $DB_USER="root";// declaring server's username
  6.     $DB_PASSWORD="";//declaring server's password
  7.     $DB_NAME="lights";// declaring the DAtabase name
  8.     $con = mysqli_connect($DB_HOST,$DB_USER,$DB_PASSWORD,$DB_NAME);//establishing a connection with database
  9.     if($_SERVER['REQUEST_METHOD']=='POST')//checking if the request made is using the method post
  10.     {
  11.         $F_name = $_POST['f_name'];//using the post method we are getting the value of 'f_name' and storing it in $F_name.The $_POST variable is used to collect values from a form with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send;
  12.         $L_name = $_POST['L_name'];//using the post method we are getting the value of 'L_name' and storing it in $L_name.The $_POST variable is used to collect values from a form with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send;
  13.         $email =  $_POST['email']; //using the post method we are getting the value of 'email' and storing it in $emails.The $_POST variable is used to collect values from a form with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send;
  14.         $password = $_POST['password'];//using the post method we are getting the value of 'password' from the app and storing it in $password.The $_POST variable is used to collect values from a form with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send;
  15.         $key = $_POST['product_key'];// //using the post method we are getting the value of 'product_key' and storing it in $key.The $_POST variable is used to collect values from a form with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send;
  16.         $CheckSQL = "SELECT * FROM userlogintable WHERE user_email='$email'";//A simple MySQL query;
  17.         $check = mysqli_fetch_array(mysqli_query($con,$CheckSQL));//as stated above mysqli_query executes a mysql statement and mysqli_fetch_array stores it in numeric or associative array;
  18.         if(isset($check)) //checking if there already exist a email in the table
  19.         {
  20.             echo 'Email Already Exist'; // if condition above is true "Email Already Exist" is printed on screen and on app toast message appears
  21.         }
  22.         if($key != "M14SK19SN25LS07D")// validating the key
  23.         {
  24.             echo 'Product Key is wrong';// if the product key is wrong the following message is displayed using toast message in the app.
  25.         }
  26.         else// if every "if" statement above is false then the value is inserted in the table named userlogintable
  27.         {
  28.             $Sql_Query = "INSERT INTO `userlogintable` (`first_name`,`last_name`,`user_email`,`user_password`) values ('$F_name','$L_name','$email','$password')"; 
  29.             if(mysqli_query($con,$Sql_Query))  
  30.             {
  31.                 echo 'Registration Successfully';
  32.             }
  33.             else
  34.             {
  35.             echo 'Something went wrong';
  36.             }  
  37.         }
  38.     }
  39. mysqli_close($con);//closing connection
  40. ?>
Add Comment
Please, Sign In to add comment