Guest User

Untitled

a guest
Mar 12th, 2018
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. <?php
  2. $dbcon=null;
  3. function connect_db()
  4. {
  5. global $dbcon;
  6. $dbcon=mysqli_connect("localhost", "root", "","classicmodels");
  7. if (!$dbcon)
  8. {
  9. echo( "<b>Unable to connect to the database server at this time.</b>" );
  10. exit();
  11. }
  12. return $dbcon;
  13. }
  14. function close_db()
  15. {
  16. global $dbcon;
  17. mysqli_close($dbcon);
  18. }
  19. ?>
  20.  
  21. <?php
  22. include "newdb.php";
  23. $dbcon=connect_db();
  24. ?>
  25. <?php
  26. $username=$_POST["username"];
  27. $password=$_POST["password"];
  28. //$username='selva';
  29. //$password='password';
  30. $flag=0;
  31. $statement="SELECT userid FROM users where username='$username' and password='$password'";
  32. //echo $statement;
  33. //exit();
  34. $result=mysqli_query($dbcon,$statement);
  35. while($row=mysqli_fetch_array($result) )
  36. {
  37. $flag=1;
  38. }
  39. close_db();
  40. if($flag==1)
  41. {
  42. $myObj=new \stdClass();
  43. $myObj->result = "1";
  44. $myJSON = json_encode($myObj);
  45. echo $myJSON;
  46. exit();
  47. }
  48. else
  49. {
  50. $myObj=new \stdClass();
  51. $myObj->result = "2";
  52. $myJSON = json_encode($myObj);
  53. echo $myJSON;
  54. exit();
  55. }
  56. ?>
Add Comment
Please, Sign In to add comment