Advertisement
Guest User

Untitled

a guest
Mar 19th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. <?php
  2. $servername = "127.0.0.1";
  3. $username = "root";
  4. $password = "root";
  5.  
  6. try {
  7. $conn = new PDO("mysql:host=$servername;port=8889;dbname=dbtest", $username, $password);
  8. // set the PDO error mode to exception
  9. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  10. echo "Connected successfully";
  11. }
  12. catch(PDOException $e)
  13. {`enter code here`
  14. echo "Connection failed: " . $e->getMessage();
  15. }
  16. ?>
  17.  
  18. <?php
  19. include("config.php");
  20. session_start();
  21.  
  22. if($_SERVER["REQUEST_METHOD"] == "POST") {
  23. // username and password sent from form
  24.  
  25. $myusername = mysqli_real_escape_string($conn,$_POST['username']);
  26. $mypassword = mysqli_real_escape_string($conn,$_POST['password']);
  27.  
  28. $sql = "SELECT id FROM users WHERE user_name = '$myusername' and user_pass = '$mypassword'";
  29. $result = mysqli_query($conn,$sql);
  30. $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
  31. $active = $row['active'];
  32.  
  33. $count = mysqli_num_rows($result);
  34.  
  35. // If result matched $myusername and $mypassword, table row must be 1 row
  36.  
  37. if($count == 1) {
  38. session_register("myusername");
  39. $_SESSION['login_user'] = $myusername;
  40.  
  41. header("location: welcome.php");
  42. }else {
  43. $error = "Your Login Name or Password is invalid";
  44. }
  45. }
  46. ?>
  47. <html>
  48.  
  49. <head>
  50. <title>Login Page</title>
  51.  
  52. <style type = "text/css">
  53. body {
  54. font-family:Arial, Helvetica, sans-serif;
  55. font-size:14px;
  56. }
  57.  
  58. label {
  59. font-weight:bold;
  60. width:100px;
  61. font-size:14px;
  62. }
  63.  
  64. .box {
  65. border:#666666 solid 1px;
  66. }
  67. </style>
  68.  
  69. </head>
  70.  
  71. <body bgcolor = "#FFFFFF">
  72.  
  73. <div align = "center">
  74. <div style = "width:300px; border: solid 1px #333333; " align = "left">
  75. <div style = "background-color:#333333; color:#FFFFFF; padding:3px;"><b>Login</b></div>
  76.  
  77. <div style = "margin:30px">
  78.  
  79. <form action = "" method = "post">
  80. <label>UserName :</label><input type = "text" name = "username" class = "box"/><br /><br />
  81. <label>Password :</label><input type = "password" name = "password" class = "box" /><br/><br />
  82. <input type = "submit" value = " Submit "/><br />
  83. </form>
  84.  
  85. <div style = "font-size:11px; color:#cc0000; margin-top:10px"><?php echo $error; ?></div>
  86.  
  87. </div>
  88.  
  89. </div>
  90.  
  91. </div>
  92.  
  93. </[enter image description here][1]body>
  94. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement