Advertisement
Guest User

Untitled

a guest
Jan 10th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. <?php
  2. //checking if the script received a post request or not
  3. if($_SERVER['REQUEST_METHOD']=='POST'){
  4.  
  5. //Getting post data
  6. $name = $_POST['name'];
  7. $username = $_POST['username'];
  8. $password = $_POST['password'];
  9. $email = $_POST['email'];
  10.  
  11. //checking if the received values are blank
  12. if($name == '' || $username == '' || $password == '' || $email == ''){
  13. //giving a message to fill all values if the values are blank
  14. echo 'please fill all values';
  15. }else{
  16. //If the values are not blank
  17. //Connecting to our database by calling dbConnect script
  18. require_once('dbConnect.php');
  19.  
  20. //Creating an SQL Query to insert into database
  21. //Here you may need to change the retrofit_users because it is the table I created
  22. //if you have a different table write your table's name
  23.  
  24. //This query is to check whether the username or email is already registered or not
  25. $sql = "SELECT * FROM ats WHERE username='$username' OR email='$email'";
  26.  
  27. //If variable check has some value from mysqli fetch array
  28. //That means username or email already exist
  29. $check = mysqli_fetch_array(mysqli_query($con,$sql));
  30.  
  31. //Checking check has some values or not
  32. if(isset($check)){
  33. //If check has some value that means username already exist
  34. echo 'username or email already exist';
  35. }else{
  36. //If username is not already exist
  37. //Creating insert query
  38. $sql = "INSERT INTO ats (name,username,password,email) VALUES('$name','$username','$password','$email')";
  39.  
  40. //Trying to insert the values to db
  41. if(mysqli_query($con,$sql)){
  42. //If inserted successfully
  43. echo 'successfully registered';
  44. }else{
  45. //In case any error occured
  46. echo 'oops! Please try again!';
  47. }
  48. }
  49. //Closing the database connection
  50. mysqli_close($con);
  51. }
  52. }else{
  53. echo 'error';
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement