Advertisement
etandel

register.php

Dec 18th, 2014
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * These are the database login details
  5. */
  6. $username = "a2083177_mydb";
  7. $password = "password1";
  8. $db="a2083177_mydb";
  9.  
  10.  
  11. // Create connection
  12. $mysqli = new mysqli('mysql17.000webhost.com', $username, $password, $db);
  13.  
  14.  
  15. ?>
  16.  
  17. <html>
  18. <body>
  19. <head>
  20. <title>Welcome to E-Box</title>
  21. <link rel="stylesheet" type="text/css" href="css/mystyle.css">
  22. <style>
  23. .error {color: #FF0000;}
  24. body
  25. {
  26. background-image: url("images/titlelogo.jpg");
  27. background-repeat:no-repeat;
  28. }
  29. </style>
  30. </head>
  31. <body>
  32.  
  33.  
  34. <?php
  35. // define variables and set to empty values
  36. $firstnameErr = $surnameErr = $usernameErr = $emailErr = $passwordErr ="";
  37. $firstname = $surname = $username = $email = $password = "";
  38.  
  39. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  40. if (empty($_POST["firstname"])) {
  41. $firstnameErr = "firstname is required";
  42. } else {
  43. $firstname = test_input($_POST["firstname"]);
  44. // check if name only contains letters and whitespace
  45. if (!preg_match("/^[a-zA-Z ]*$/",$firstname))
  46. {
  47. $firstnameErr = "Only letters and white space allowed";
  48. }
  49. }
  50.  
  51. if (empty($_POST["surname"])) {
  52. $surnameErr = "Surname is required";
  53. } else {
  54. $surname = test_input($_POST["surname"]);
  55. }
  56.  
  57. if (empty($_POST["username"])) {
  58. $usernameErr = "Username is required";
  59. } else {
  60. $username = test_input($_POST["username"]);
  61. }
  62.  
  63. if (empty($_POST["email"])) {
  64. $emailErr = "Email is required";
  65. } else {
  66. $email = test_input($_POST["email"]);
  67. if (!filter_var($email, FILTER_VALIDATE_EMAIL))
  68. {
  69. $emailErr = "Invalid email format";
  70. }
  71. }
  72.  
  73. if (empty($_POST["password"])) {
  74. $passwordErr = "Password is required";
  75. } else {
  76. $password = test_input($_POST["password"]);
  77. }
  78. }
  79.  
  80. $sql = "INSERT INTO userdata (firstname, surname, username, email, password)
  81. VALUES ('$firstname', '$surname', '$username', '$email', '$password')";
  82.  
  83. if ($mysqli->query($sql) === TRUE) {
  84. echo "";
  85. } else {
  86. echo "Error: " . $sql . "<br>" . $mysqli->error;
  87. }
  88.  
  89. $mysqli->close();
  90.  
  91. function test_input($data) {
  92. $data = trim($data);
  93. $data = stripslashes($data);
  94. $data = htmlspecialchars($data);
  95. return $data;
  96. }
  97. ?>
  98.  
  99. <div class="newuser">
  100. <p style="margin-left:-350px; margin-top:50px; font-family:arial; font-size:20px;">Register</P>
  101. </div>
  102. <p><span class="error" style="margin-left:450px;">* required field.<a href="index.php" style="margin-left:205px;"> Log in </a></span></p>
  103.  
  104. <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
  105. <div class="register">
  106.  
  107. <input class="textbox" type="text" name="firstname" placeholder=" First name" value="<?php echo $firstname;?>">
  108. <span class="error">* <?php echo $firstnameErr;?></span></br></br>
  109.  
  110. <input class="textbox" type="text" name="surname" placeholder="Surname" value="<?php echo $surname;?>">
  111. <span class="error">* <?php echo $surnameErr;?></span></br></br>
  112.  
  113. <input class="textbox" type="text" name="username" placeholder="Username" value="<?php echo $username;?>">
  114. <span class="error">* <?php echo $usernameErr;?></span></br></br>
  115.  
  116. <input class="textbox" type="text" name="email" placeholder="E-mail" value="<?php echo $email;?>">
  117. <span class="error">* <?php echo $emailErr;?></span></br></br>
  118.  
  119. <input class="textbox" type="password" name="password" placeholder="Password" value="<?php echo $password;?>">
  120. <span class="error">* <?php echo $passwordErr;?></span></br></br>
  121. <input class="bluebutton" style="margin-left:270;" type="submit" value="Register" name="register" onclick="myFunction()">
  122. </div>
  123. </form>
  124. <script>
  125. function myFunction() {
  126. alert("You are successfully registered!");
  127. }
  128. </script>
  129.  
  130. <!--
  131. <div id="userinfo">
  132. <?php
  133. echo "<br><br><br><br><br><h2><strong>You are successfully registered.</strong></h2>";
  134. echo "<h3>Your information:</h3>";
  135. echo "First name : ";
  136. echo $firstname;
  137. echo "<br>";
  138. echo "Surname : ";
  139. echo $Surname;
  140. echo "<br>";
  141. echo "User name : ";
  142. echo $username;
  143. echo "<br>";
  144. echo "E-mail : ";
  145. echo $email;
  146. echo "<br>";
  147. echo "Password : ";
  148. echo $password;
  149. ?>
  150. </div>
  151. -->
  152. </body>
  153. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement