Advertisement
Guest User

Untitled

a guest
Mar 10th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1.  
  2.  
  3.  
  4. <?php
  5. // define variables and initialize with empty values
  6. $nameErr = $passErr = $emailErr =$cpassErr="";
  7. $name = $pass = $cpass = $email = "";
  8.  
  9.  
  10.  
  11. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  12. if (empty($_POST["username"])) {
  13. $nameErr = "Enter Username";
  14.  
  15. }
  16. else {
  17. $name = $_POST["username"];
  18. }
  19.  
  20. if (empty($_POST["password"])) {
  21. $passErr = "Enter password";
  22.  
  23. }
  24. else {
  25. $pass = $_POST["password"];
  26. }
  27. if (empty($_POST["cpassword"])) {
  28. $cpassErr = "Retype password";
  29.  
  30. }
  31. else {
  32. $cpass= $_POST["cpassword"];
  33. }
  34.  
  35. if (empty($_POST["email"])) {
  36. $emailErr = "Enter email";
  37.  
  38. }
  39. else {
  40. $email = $_POST["email"];
  41. }
  42.  
  43.  
  44. }
  45.  
  46.  
  47. ?>
  48.  
  49. <html>
  50. <head>
  51. <style>
  52. .error {
  53. color: #FF0000;
  54. }
  55. </style>
  56. </head>
  57. <body>
  58. <form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
  59. <table border="0" cellspacing="20">
  60. <tbody>
  61. <tr>
  62. <td>Username:</td>
  63. <td><input type="text" name="username" accept="" value="<?php echo htmlspecialchars($name);?>">
  64. <span class="error"><?php echo $nameErr;?></span>
  65. </td>
  66. </tr>
  67. <tr>
  68. <td>Password:</td>
  69. <td><input type="text" name="password" accept="" value="<?php echo htmlspecialchars($pass);?>">
  70. <span class="error"><?php echo $passErr;?></span></td>
  71. </tr>
  72. <tr>
  73. <td>Confirm Password:</td>
  74. <td><input type="text" name="cpassword" accept=""value="<?php echo htmlspecialchars($cpass);?>">
  75. <span class="error"><?php echo $cpassErr;?></span></td>
  76. </tr>
  77. <tr>
  78. <td>Email:</td>
  79. <td><input type="text" name="email" accept="" value="<?php echo htmlspecialchars($email);?>">
  80. <span class="error"><?php echo $emailErr;?></span></td></td>
  81. </tr>
  82. </tbody>
  83. </table>
  84. <input type="submit" name="submit" value="Submit">
  85. </form>
  86. </body>
  87.  
  88. </html>
  89. <?php
  90. $host="localhost";
  91. $username="root";
  92. $password="password";
  93. $db_name="LSDB";
  94.  
  95. $u=striptags($_POST['username']);
  96. $p=striptags($_POST['password']);
  97. $e=filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
  98. $ph=(int)$_POST['phone'];
  99.  
  100. $mysqli = new mysqli($host,$username,$password,$db_name);
  101. $query = "INSERT INTO register (username,password,email) VALUES (?,?,?)";
  102. $stmt = $mysqli->prepare($query);
  103. $stmt->bind_param("sssi", $u, $p, $e, $ph);
  104. $stmt->execute();
  105. $mysqli->close();
  106.  
  107. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement