Advertisement
Guest User

Untitled

a guest
Jun 14th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. html:
  2.  
  3. <!DOCTYPE html>
  4. <html>
  5. <head>
  6. <meta charset="UTF-8">
  7. <title></title>
  8. </head>
  9. <body>
  10. <form name="form1" action="process_register.php" method="POST">
  11. <input type="hidden" name="check_submit" value="1"/>
  12. Username:<br>
  13. <input type="text" name="username"><br>
  14. Password (8 characters at least):<br>
  15. <input type="password" name="password" maxlength="20"><br><br>
  16.  
  17. <br><br>Click the option that you require:<br>
  18. <input type="radio" name="inputting" value="signin" checked="checked"/>Sign-In
  19. <input type="radio" name="inputting" value="register" />Register
  20. <br><br>
  21. <input type="submit" name="submit">
  22. </form>
  23. <?php
  24.  
  25. ?>
  26. </body>
  27. </html>
  28.  
  29. php:
  30.  
  31.  
  32. <!DOCTYPE html>
  33. <!--
  34. To change this license header, choose License Headers in Project Properties.
  35. To change this template file, choose Tools | Templates
  36. and open the template in the editor.
  37. -->
  38. <html>
  39. <head>
  40. <meta charset="UTF-8">
  41. <title></title>
  42. </head>
  43. <body>
  44. <?php
  45.  
  46. $user = $_POST['username'];
  47. $pass = $_POST['password'];
  48. $choice = $_POST['inputting'];
  49.  
  50. $servername = "localhost";
  51. $username = "seenanfb";
  52. $password = "password1234";
  53. $dbname = "phpDB";
  54.  
  55. $conn = new mysqli($servername, $username, $password, $dbname);
  56.  
  57. // Check connection
  58. if ($conn->connect_error) {
  59. die("Connection failed: " . $conn->connect_error);
  60. }
  61. //echo "Connected successfully";
  62.  
  63. $db1 = "CREATE DATABASE phpDBx";
  64. if ($conn->query($db1) === TRUE) {
  65. echo "Database created successfully";
  66. } else {
  67. //echo "Error creating database: " . $conn->error;
  68. }
  69.  
  70. $table = "CREATE TABLE phpform (
  71. id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  72. username VARCHAR(30) NOT NULL,
  73. password VARCHAR(20) NOT NULL
  74. )";
  75.  
  76. if ($conn->query($table) === TRUE) {
  77. echo "Table phpform created successfully";
  78. } else {
  79. //echo "Error creating table: " . $conn->error;
  80. }
  81.  
  82.  
  83. if (strlen($user) < 6){
  84. echo "Usernames must be at least 6 characters";
  85. return;
  86. }
  87. else
  88. //echo "Username Accepted";
  89.  
  90.  
  91. if (strlen($pass) < 8){
  92. echo "Password must be at least 8 characters";
  93. return;
  94. }
  95. else
  96. //echo "Password Accepted";
  97.  
  98.  
  99. $selectstmt = "SELECT 'username' FROM 'phpform' WHERE 'username' = ?";
  100. if($choice === "signin")
  101. {
  102. $stmt = $conn->prepare($selectstmt);
  103. $stmt->bind_param('s', $username);
  104. $stmt->execute();
  105. $result = $stmt->get_result();
  106. if($result){
  107. echo "Hurray, you signed in";
  108. }
  109. else
  110. echo "Sign-In not found. Please register first.";
  111. }
  112.  
  113. $regstmt = "INSERT INTO phpform (username, password) VALUES(?, ?)";
  114. if($choice === "register")
  115. {
  116. if($stmt = $conn->prepare($regstmt))
  117. {
  118. $stmt->bind_param('ss', $user, $pass);
  119. //$stmt->bind_param('s', $pass);
  120. $stmt->execute();
  121. //$stmt->bind_result($phpform);
  122. $result = $stmt->get_result();
  123. //$stmt->fetch();
  124. if($result)
  125. echo "Yay, you registered";
  126. else
  127. echo "Registry failed";
  128. }
  129. else{
  130. echo ":(";
  131. var_dump($user, $pass);
  132. }
  133. }
  134.  
  135.  
  136. $conn->close();
  137.  
  138.  
  139. ?>
  140. </body>
  141. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement