Guest User

Untitled

a guest
Jan 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. <?php
  2. error_reporting(0);
  3. $dbcon=new mysqli("localhost","root","","php");
  4. // $dbcon=new mysqli("servername","username","password","databasename");
  5.  
  6. //check databse is connected
  7. if($dbcon->connect_error)
  8. {
  9. die("Error : ".$dbcon->connect_error);
  10. }
  11.  
  12. //signup function
  13. function signup($fullname,$username,$password)
  14. {
  15. global $dbcon;
  16. $sql="INSERT INTO `user` (`user_id`, `username`, `fullname`, `password`) VALUES ('', '$username', '$fullname', '$password')";
  17. $result=$dbcon->query($sql);
  18. if($result===true)
  19. {
  20. return true;
  21. }
  22. else
  23. {
  24. return false;
  25. }
  26. }
  27.  
  28. //performing signup
  29. if($_SERVER['REQUEST_METHOD'] == 'POST')
  30. {
  31. $username=$_POST['username'];
  32. $fullname=$_POST['fullname'];
  33. $password=$_POST['password'];
  34.  
  35. if($username=="")
  36. {
  37. echo json_encode(array("error"=>true,"message"=>"Please Provide Username"));
  38. }
  39. else if(signup($fullname,$username,$password))
  40. {
  41. echo json_encode(array("error"=>false,"message"=>"Data save in database"));
  42. }
  43. else
  44. {
  45. echo json_encode(array("error"=>true,"message"=>"Same data not allows"));
  46. }
  47.  
  48. }
  49. else
  50. {
  51. echo json_encode(array("error"=>true,"message"=>"Only POST Method allows"));
  52. }
Add Comment
Please, Sign In to add comment