Advertisement
Guest User

Untitled

a guest
Feb 7th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. <!-- dbconnection.php -->
  2. <?php
  3. $dbname = 'loggin';
  4. $hostname = 'localhost';
  5. $username = 'root';
  6. $password = '';
  7. $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'");
  8.  
  9. try {
  10. $dbConn = new PDO("mysql:host=$hostname;dbname=$dbname;", $username,
  11. $password, $options);
  12. $dbConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  13. /*** echo a message saying we have connected ***/
  14. echo 'Connected to database.<br />';
  15. }
  16. catch(PDOException $e){
  17. // For debug purpose, shows all connection details
  18. echo 'Connection failed: '.$e->getMessage()."<br />";
  19. // Hide connection details.
  20. //echo 'Could not connect to database.<br />');
  21. }
  22.  
  23. --------------------
  24.  
  25.  
  26. <!--createTable.php-->
  27. <?php
  28. include('databaseConnection.php');
  29. try{
  30.  
  31. $sql = "CREATE TABLE Users(
  32. userID INT(6) AUTO_INCREMENT PRIMARY KEY,
  33. userName VARCHAR(30) NOT NULL,
  34. email VARCHAR(30) NOT NULL,
  35. password VARCHAR(255) NOT NULL
  36. )";
  37.  
  38. $dbConn->exec($sql);
  39. echo "Table created succesfully!";
  40. }
  41. catch(PDOexeption $e){
  42. echo $sql. "<br>". $e->getMessage();
  43. }
  44.  
  45. $dbConn = null;
  46.  
  47. ?>
  48.  
  49.  
  50.  
  51. -------------
  52.  
  53.  
  54.  
  55. <!--registerNewUser.php-->
  56. <!DOCTYPE html>
  57. <html>
  58. <head>
  59. <title>AddUser</title>
  60. </head>
  61. <body>
  62. <form method="POST" action="">
  63. <input type="text" name="username" placeholder="username">
  64. <input type="text" name="email" placeholder="Email">
  65. <input type="password" name="password" placeholder="Password">
  66. <input type="submit" name="send">
  67. </form>
  68.  
  69. <?php
  70. include('databaseConnection.php');
  71.  
  72.  
  73. if (isset($_POST['send']))
  74. {
  75. $username = $_POST['username'];
  76. $email = $_POST['email'];
  77. $password = $_POST['password'];
  78.  
  79.  
  80.  
  81. function cryptFu($username, $email, $password, $dbConn)
  82. {
  83. $md5crypt = md5($username);
  84. $cryptusername = crypt($username, "!!!". $md5crypt);
  85. $cryptEmail = crypt($email, "!!!". $md5crypt);
  86. $cryptPassword = crypt($password, "!!!". $md5crypt);
  87. addDb($cryptusername, $cryptEmail, $cryptPassword, $dbConn);
  88. echo"1";
  89. }
  90.  
  91. function addDb($username, $email, $password, $dbConn)
  92. {
  93. echo"2";
  94. try{
  95. $sql = "INSERT INTO users (username, email, password) VALUES('$username', '$email', '$password')";
  96. $dbConn->exec($sql);
  97. }
  98. catch(PDOException $e){
  99. echo $sql . "<br>" . $e->getMessage();
  100. }
  101. }
  102. cryptFu($username, $email, $password , $dbConn);
  103.  
  104. }
  105. ?>
  106. </body>
  107. </html>
  108.  
  109. --------------- MY PROBLEMS START HERE!
  110. <!--loggin.php-->
  111. <!DOCTYPE html>
  112. <html>
  113. <head>
  114. <title>Loggin</title>
  115. </head>
  116. <body>
  117.  
  118. <?php
  119. include('databaseConnection.php');
  120.  
  121. if (isset($_POST['send']))
  122. {
  123. $username = $_POST["username"];
  124. $password = $_POST["password"];
  125.  
  126. $sql = "SELECT password FROM users WHERE userName = '$username' ";
  127. $stmt = $dbConn->prepare($sql);
  128.  
  129. $data = array();
  130. $stmt->execute($data);
  131. $res = $stmt->fetch(PDO::FETCH_ASSOC);
  132. $output = htmlentities(print_r($res, 1));
  133. echo "<pre>$output</pre>";
  134. }
  135. ?>
  136.  
  137. <form method ="POST" action ="">
  138. <input type="text" name="username">
  139. <input type="password" name="password">
  140. <input type="submit" name="send">
  141. </form>
  142.  
  143. </body>
  144. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement