Advertisement
Guest User

Untitled

a guest
Jul 12th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.36 KB | None | 0 0
  1. <?php
  2. require('config.php');
  3. // If the values are posted, insert them into the database.
  4. if (isset($_POST['username']) && isset($_POST['password'])){
  5. $username = $_POST['username'];
  6. $email = $_POST['email'];
  7. $password = $_POST['password'];
  8. $cpassword = $_POST['confirmpassword'];
  9. $slquery = "SELECT 1 FROM register WHERE email = '$email'";
  10. $selectresult = mysql_query($slquery);
  11. if(mysql_num_rows($selectresult)>0)
  12. {
  13. die('email already exists');
  14. }
  15.  
  16. $query = "INSERT INTO `register` (username, password,confirmpassword, email) VALUES ('$username', '$password', '$cpassword', '$email')";
  17. $result = mysql_query($query);
  18. if($result){
  19. $msg = "User Created Successfully.";
  20. }
  21. }
  22. ?>
  23. <!DOCTYPE html>
  24. <html>
  25. <head>
  26. <title>Login screen</title>
  27. <style type="text/css">
  28. .register-form{
  29. width: 500px;
  30. margin: 0 auto;
  31. text-align: center;
  32. padding: 10px;
  33. padding: 10px;
  34. background : #c4c4c4;
  35. border-radius: 10px;
  36. -webkit-border-radius:10px;
  37. -moz-border-radius:10px;
  38. }
  39. .register-form form input{padding: 5px;}
  40. .register-form .btn{
  41. background: #726E6E;
  42. padding: 7px;
  43. border-radius: 5px;
  44. text-decoration: none;
  45. width: 50px;
  46. display: inline-block;
  47. color: #FFF;
  48. }
  49. .register-form .register{
  50. border: 0;
  51. width: 60px;
  52. padding: 8px;
  53. }
  54. </style>
  55. </head>
  56. <body>
  57. <div class="register-form">
  58. <?php
  59. if(isset($msg) & !empty($msg)){
  60. echo $msg;
  61. }
  62. ?>
  63. <?php
  64. if(isset($errormes))
  65. {
  66. echo $errormes;
  67. }
  68. ?>
  69. <h1>Register</h1>
  70. <form action="" method="POST">
  71. <p><label>User Name: </label>
  72. <input type="text" id="username" name="username" placeholder="Username">
  73. </p>
  74. <p><label>E-Mail&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :</label>
  75. <input id="email" name="email" type="email">
  76. </p>
  77. <p><label>Password&nbsp;&nbsp; :</label>
  78. <input id="password" name="password" type="password">
  79. </p>
  80. <p><label>confirm Password &nbsp;&nbsp; :</label>
  81. <input id="confirmpassword" name="confirmpassword" type="password">
  82. </p>
  83. <input type="submit" name="submit" value="register" class="btn register">
  84. <a class="btn" href="login.php">Login</a>
  85. </form>
  86. </div>
  87. </body>
  88. </html>
  89.  
  90. <?php
  91. require('config.php');
  92. // If the values are posted, insert them into the database.
  93. if (isset($_POST['username']) && isset($_POST['password'])){
  94. $username = $_POST['username'];
  95. $email = $_POST['email'];
  96. $password = $_POST['password'];
  97. $cpassword = $_POST['confirmpassword'];
  98. $slquery = "SELECT 1 FROM register WHERE email = '$email'";
  99. $selectresult = mysql_query($slquery);
  100. if(mysql_num_rows($selectresult)>0)
  101. {
  102. $msg = 'email already exists';
  103. }
  104. elseif($password != $cpassword){
  105. $msg = "passwords doesn't match";
  106. }
  107. else{
  108. $query = "INSERT INTO `register` (username, password,confirmpassword, email) VALUES ('$username', '$password', '$cpassword', '$email')";
  109. $result = mysql_query($query);
  110. if($result){
  111. $msg = "User Created Successfully.";
  112. }
  113. }
  114. }
  115. ?>
  116.  
  117. <?php
  118.  
  119. require_once('config.php');
  120.  
  121. // function for email validation
  122. function is_valid_email($mail)
  123. {
  124. if (empty($mail)) {
  125. echo "Email is required.";
  126. return false;
  127. } else {
  128. $email = test_input($mail);
  129. // check if e-mail address is well-formed
  130. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  131. echo "Invalid email format.";
  132. return false;
  133. }
  134. // now check if the mail is already registered
  135. $slquery = "SELECT 1 FROM register WHERE email = '$email'";
  136. $selectresult = mysql_query($slquery);
  137. if(mysql_num_rows($selectresult)>0) {
  138. echo 'This email already exists.';
  139. return false;
  140. }
  141. // now returns the true- means you can proceed with this mail
  142. return true;
  143. }
  144.  
  145. // function for password verification
  146. function is_valid_passwords($pass,$confirmpass)
  147. {
  148. // Your validation code.
  149. if (empty($pass)) {
  150. echo "Password is required.";
  151. return false;
  152. }
  153. else if ($pass != $confirmpass) {
  154. // error matching passwords
  155. echo 'Your passwords do not match. Please type carefully.';
  156. return false;
  157. }
  158. // passwords match
  159. return true;
  160. }
  161.  
  162. // function for creating user
  163. function create_user($username, $password, $cpassword, $email)
  164. {
  165. $query = "INSERT INTO `register` (username, password, confirmpassword, email) VALUES ('$username', '$password', '$cpassword', '$email')";
  166. $result = mysql_query($query);
  167. if($result){
  168. return true; // Success
  169. }else{
  170. return false; // Error somewhere
  171. }
  172. }
  173.  
  174. // Code execution starts here when submit
  175. if (isset($_POST['username']) && isset($_POST['password'])){
  176.  
  177. // Reading form values
  178. $username = $_POST['username'];
  179. $email = $_POST['email'];
  180. $password = $_POST['password'];
  181. $cpassword = $_POST['confirmpassword'];
  182.  
  183. if (is_valid_email($email) && is_valid_passwords($password,$cpassword))
  184. {
  185. if (create_user($username, $password, $cpassword, $email)) {
  186. echo 'New User Registered Successfully.';
  187. }else{
  188. echo 'Error Registering User!';
  189. }
  190. }
  191. // You don't need to write another 'else' since this is the end of PHP code
  192. ?>
  193.  
  194. <!-- Here you go with the HTML -->
  195.  
  196. <!DOCTYPE html>
  197. <html>
  198. <head>
  199. <title>Login screen</title>
  200. <style type="text/css">
  201. .register-form{
  202. width: 500px;
  203. margin: 0 auto;
  204. text-align: center;
  205. padding: 10px;
  206. padding: 10px;
  207. background : #c4c4c4;
  208. border-radius: 10px;
  209. -webkit-border-radius:10px;
  210. -moz-border-radius:10px;
  211. }
  212. .register-form form input{padding: 5px;}
  213. .register-form .btn{
  214. background: #726E6E;
  215. padding: 7px;
  216. border-radius: 5px;
  217. text-decoration: none;
  218. width: 50px;
  219. display: inline-block;
  220. color: #FFF;
  221. }
  222. .register-form .register{
  223. border: 0;
  224. width: 60px;
  225. padding: 8px;
  226. }
  227. </style>
  228. </head>
  229. <body>
  230. <div class="register-form">
  231. <h1>Register</h1>
  232. <form action="" method="POST">
  233. <p><label>User Name: </label>
  234. <input type="text" id="username" name="username" placeholder="Username">
  235. </p>
  236. <p><label>E-Mail&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :</label>
  237. <input id="email" name="email" type="email">
  238. </p>
  239. <p><label>Password&nbsp;&nbsp; :</label>
  240. <input id="password" name="password" type="password">
  241. </p>
  242. <p><label>confirm Password &nbsp;&nbsp; :</label>
  243. <input id="confirmpassword" name="confirmpassword" type="password">
  244. </p>
  245. <input type="submit" name="submit" value="register" class="btn register">
  246. <a class="btn" href="login.php">Login</a>
  247. </form>
  248. </div>
  249. </body>
  250. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement