SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | // require_once("connection.php");
| |
| 3 | // session_start(); | |
| 4 | // define variables and set to empty values | |
| 5 | ||
| 6 | $clientFirstName = $clientLastName = $clientEmail = $clientPassword = $clientCPassword = $clientContact = ""; | |
| 7 | ||
| 8 | if ($_SERVER["REQUEST_METHOD"] == "POST") {
| |
| 9 | ||
| 10 | // First Name Validation | |
| 11 | if (empty($_POST["clientFirstName"])) {
| |
| 12 | ||
| 13 | die("error: empty field");
| |
| 14 | } else {
| |
| 15 | $clientFirstName = test_input($_POST["clientFirstName"]); | |
| 16 | // check if name only contains letters and whitespace | |
| 17 | if (!preg_match("/[a-zA-Z ]/", $clientFirstName)) {
| |
| 18 | ||
| 19 | die("Error: Only letters and white space allowed");
| |
| 20 | ||
| 21 | } | |
| 22 | } | |
| 23 | ||
| 24 | // Last Name Validation | |
| 25 | ||
| 26 | if (empty($_POST["clientLastName"])) {
| |
| 27 | ||
| 28 | die("error: empty field");
| |
| 29 | ||
| 30 | } else {
| |
| 31 | ||
| 32 | $clientLastName = test_input($_POST["clientLastName"]); | |
| 33 | ||
| 34 | // check if name only contains letters and whitespace | |
| 35 | ||
| 36 | if (!preg_match("/[a-zA-Z ]/", $clientLastName)) {
| |
| 37 | ||
| 38 | ||
| 39 | die("Error: Only letters and white space allowed");
| |
| 40 | } | |
| 41 | ||
| 42 | } | |
| 43 | ||
| 44 | // Email Validation | |
| 45 | ||
| 46 | if (empty($_POST["clientEmail"])) {
| |
| 47 | ||
| 48 | die("error: empty field");
| |
| 49 | ||
| 50 | } else {
| |
| 51 | ||
| 52 | $clientEmail = test_input($_POST["clientEmail"]); | |
| 53 | ||
| 54 | // check if e-mail address is well-formed | |
| 55 | ||
| 56 | if (!filter_var($clientEmail, FILTER_VALIDATE_EMAIL)) {
| |
| 57 | ||
| 58 | die("Error: Invalid email format");
| |
| 59 | ||
| 60 | } | |
| 61 | ||
| 62 | } | |
| 63 | ||
| 64 | // Password Validation | |
| 65 | ||
| 66 | if (empty($_POST["clientPassword"])) {
| |
| 67 | ||
| 68 | die("error: empty field");
| |
| 69 | ||
| 70 | } | |
| 71 | ||
| 72 | // Confirm Password Validation | |
| 73 | ||
| 74 | if (empty($_POST["clientCPassword"])) {
| |
| 75 | ||
| 76 | die("error: empty field");
| |
| 77 | ||
| 78 | } | |
| 79 | ||
| 80 | - | if ($clientPassword != $clientCPassword) {
|
| 80 | + | if ($_POST["clientPassword"] != $_POST["clientCPassword"]) {
|
| 81 | ||
| 82 | die("error: passwords mismatch");
| |
| 83 | ||
| 84 | ||
| 85 | } else {
| |
| 86 | ||
| 87 | $hashedClientPassword = password_hash($clientPassword, PASSWORD_DEFAULT); | |
| 88 | ||
| 89 | } | |
| 90 | ||
| 91 | if (empty($_POST["clientContact"])) {
| |
| 92 | ||
| 93 | ||
| 94 | die("error: empty field");
| |
| 95 | ||
| 96 | } else {
| |
| 97 | ||
| 98 | $clientContact = test_input($_POST["clientContact"]); | |
| 99 | ||
| 100 | // check if number is correct | |
| 101 | ||
| 102 | if (!preg_match("/[0-9]/", $clientContact)) {
| |
| 103 | ||
| 104 | die("error: Only 0-9 allowed");
| |
| 105 | } | |
| 106 | ||
| 107 | } | |
| 108 | ||
| 109 | echo 'All Passed'; | |
| 110 | ||
| 111 | // $check_email = $conn->query("SELECT clientEmail FROM tbl_clients WHERE clientEmail='$clientEmail'");
| |
| 112 | ||
| 113 | // $emailCount = $check_email->num_rows; | |
| 114 | ||
| 115 | // if ($emailCount == 0) {
| |
| 116 | ||
| 117 | // $newClient = "INSERT INTO tbl_clients(clientFirstName, clientLastName, clientEmail, clientPassword, clientContact) VALUES('$clientFirstName','$clientLastName','$clientEmail','$hashedClientPassword','$clientContact')";
| |
| 118 | ||
| 119 | // if ($newClient === false) {
| |
| 120 | ||
| 121 | // $result = array(); | |
| 122 | // $result[] = array( | |
| 123 | // "status" => "Error" | |
| 124 | // ); | |
| 125 | // } else {
| |
| 126 | // echo "Your have been signed up - please now Log In"; | |
| 127 | ||
| 128 | // $result = array(); | |
| 129 | // $result[] = array( | |
| 130 | // "First Name" => $clientFirstName, | |
| 131 | // "Last Name" => $clientLastName, | |
| 132 | // "Email" => $clientEmail, | |
| 133 | // "Password" => $hashedClientPassword, | |
| 134 | // "Contact" => $clientContact, | |
| 135 | // "status" => "success" | |
| 136 | // ); | |
| 137 | ||
| 138 | // } | |
| 139 | ||
| 140 | // } else {
| |
| 141 | ||
| 142 | // echo "Already Exists"; | |
| 143 | // $result = array(); | |
| 144 | // $result[] = array( | |
| 145 | // "status" => "Error" | |
| 146 | // ); | |
| 147 | ||
| 148 | // } | |
| 149 | ||
| 150 | // echo json_encode($result); | |
| 151 | ||
| 152 | } | |
| 153 | ||
| 154 | function test_input($data) | |
| 155 | {
| |
| 156 | ||
| 157 | $data = trim($data); | |
| 158 | ||
| 159 | $data = stripslashes($data); | |
| 160 | ||
| 161 | $data = htmlspecialchars($data); | |
| 162 | ||
| 163 | return $data; | |
| 164 | ||
| 165 | } | |
| 166 | ||
| 167 | ?> | |
| 168 | <!DOCTYPE HTML> | |
| 169 | <html> | |
| 170 | <head> | |
| 171 | ||
| 172 | </head> | |
| 173 | <body> | |
| 174 | ||
| 175 | <h2>Reg User</h2> | |
| 176 | <form method="post" action=""> | |
| 177 | <label> | |
| 178 | First Name:<input type="text" name="clientFirstName"><br/> | |
| 179 | Last Name:<input type="text" name="clientLastName"><br/> | |
| 180 | Email:<input type="text" name="clientEmail"><br/> | |
| 181 | Password:<input type="password" name="clientPassword"><br/> | |
| 182 | Confirm Password:<input type="password" name="clientCPassword"><br/> | |
| 183 | Contact:<input type="text" name="clientContact"><br/> | |
| 184 | <input type="submit" value="Register" name="submit"> | |
| 185 | </label> | |
| 186 | </form> | |
| 187 | ||
| 188 | </body> | |
| 189 | </html> |