SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | ||
| 3 | - | // Create database handle |
| 3 | + | |
| 4 | ||
| 5 | $sql = <<< SQL | |
| 6 | - | // The SQL that we will use; the question marks are |
| 6 | + | |
| 7 | - | // placeholders for where the values will be placed |
| 7 | + | |
| 8 | `D_License_No`, | |
| 9 | `Arrived_Time`, | |
| 10 | `Charge` | |
| 11 | ) VALUES ( | |
| 12 | ?, ?, ?, ? | |
| 13 | ); | |
| 14 | SQL; | |
| 15 | ||
| 16 | $stmt = $mysqli->prepare($sql); | |
| 17 | if ($stmt === false) {
| |
| 18 | die('Could not prepare SQL: '.$mysqli->error);
| |
| 19 | - | // Prepare the SQL and get a statement handle |
| 19 | + | |
| 20 | - | // Prepared queries are send to the database, which |
| 20 | + | |
| 21 | - | // checks it for errors and also optimizes it so that |
| 21 | + | |
| 22 | - | // consecutive calls to `execute()` are performed |
| 22 | + | |
| 23 | - | // faster. In this case, however, we are using a prepared |
| 23 | + | |
| 24 | - | // statement to avoid malicious data from affecting |
| 24 | + | |
| 25 | - | // the query. |
| 25 | + | |
| 26 | $vLicense = filter_input(INPUT_POST, 'V_License_No', FILTER_SANITIZE_STRING); | |
| 27 | $dLicense = filter_input(INPUT_POST, 'D_License_No', FILTER_SANITIZE_STRING); | |
| 28 | $arrived = date('H:i');
| |
| 29 | if (isset($_POST['vehicle_type']) && $_POST['vehicle_type'] === 'four_wheel') {
| |
| 30 | - | // Bind some variables to the statement |
| 30 | + | |
| 31 | - | // The bound variables here ($vLicense, $dLicense, etc.) are |
| 31 | + | |
| 32 | - | // defined here and bound to this statement. We are setting |
| 32 | + | |
| 33 | - | // the *values* of these variables further down. |
| 33 | + | |
| 34 | ||
| 35 | if ($stmt->execute() === false) {
| |
| 36 | die('Could not execute query: '.$stmt->error);
| |
| 37 | } else {
| |
| 38 | - | // Set the values of the bound variables here: |
| 38 | + | |
| 39 | } |