reenadak

mysqli connection example

Sep 25th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. <?php
  2.  
  3. define("DB_HOST", "mysql.dungla.com");
  4. define("DB_USER", "dungla");
  5. define("DB_PASS", "password");
  6. define("DB_NAME", "2017_mukeshdak");
  7.  
  8. $connection = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
  9.  
  10. if(!$connection) die("Mysqli connection failed " . mysqli_error($connection));
  11.  
  12. if( ($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST['username']))
  13. {
  14.     $username = mysqli_real_escape_string($connection, $_POST['username']);
  15.     $password = mysqli_real_escape_string($connection, $_POST['password']);
  16.     // Lines above ensures, protection against SQL injection.
  17.  
  18.     $query = "SELECT * from users where username LIKE '".$username."' ";
  19.  
  20.     $result = mysqli_query($query);
  21.  
  22.     if($result)
  23.     {
  24.         while($row = mysqli_fetch_assoc($result)
  25.         {
  26.             echo $row['username'];
  27.         }
  28.  
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment