Advertisement
pgeeweb

functions example

Dec 14th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.55 KB | None | 0 0
  1. <?php
  2. $con = NULL;
  3.  
  4. function connect($host, $user, $password, $db) {
  5.     global $con;
  6.     $con = mysqli_connect($host, $user, $password, $db);
  7. }
  8.  
  9. function user_exists($username) {
  10.     global $con;
  11.     $query = mysqli_query($con, "SELECT * FROM users WHERE username='".$username."'");
  12.     $userCount = mysqli_num_rows($query);
  13.     if($userCount!=0) {
  14.         return true;
  15.     } else {
  16.         return false;
  17.     }
  18. }
  19.  
  20. connect("localhost", "root", "", "vaflichka2");
  21.  
  22. $check = user_exists("tata");
  23. if($check==true) {
  24.     echo "User found!";
  25. } else {
  26.     echo "User not found!";
  27. }
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement