Advertisement
Guest User

Untitled

a guest
Sep 28th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. $host="";
  5. $username="";
  6. $password = "";
  7. $database="";
  8. // create a database connection
  9. $connection = mysql_connect($host,$username,$password);
  10. if(!$connection){
  11. die("Database connection failed: " . mysql_error());
  12. }
  13.  
  14. // select a database to use
  15. $db_select = mysql_select_db($database,$connection);
  16. if (!$db_select) {
  17. die("Database selectionfailed: " . mysql_error());
  18. }
  19.  
  20. if(isset($_POST['submit'])){
  21. $username = mysql_real_escape_string($_POST['username']);
  22. $password = mysql_real_escape_string($_POST['password']);
  23.  
  24. $query= mysql_query("SELECT id,username FROM user_info WHERE username='$username' AND password = '$password' LIMIT 1");
  25. $found = mysql_num_rows($query);
  26. if($found == 1){
  27. $row = mysql_fetch_assoc($query);
  28. //start sessioning the id and userame
  29. $_SESSION['id'] = $row['id'];
  30. $_SESSION['username'] = $row['username'];
  31.  
  32. //header('Location: main.php'); //redirect page
  33. echo "you're login";
  34. }else{
  35. echo "login failed";
  36. }
  37. }
  38. ?>
  39.  
  40.  
  41. <form method="POST" action="login.php">
  42. username <input type="text" name="username" id="username"><br/>
  43. password <input type="password" name="password" id="password"><br/>
  44. <input type="submit" id="submit" name="submit" value="login">
  45. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement