Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Create database handle
- $mysqli = new MySQLi('localhost', 'root', '11111', 'CAR_PARKING_SYSTEM');
- // The SQL that we will use; the question marks are
- // placeholders for where the values will be placed
- $sql = <<< SQL
- INSERT INTO `CUSTOMER_VEHICLE` (
- `V_License_No`,
- `D_License_No`,
- `Arrived_Time`,
- `Charge`
- ) VALUES (
- ?, ?, ?, ?
- );
- SQL;
- // Prepare the SQL and get a statement handle
- // Prepared queries are send to the database, which
- // checks it for errors and also optimizes it so that
- // consecutive calls to `execute()` are performed
- // faster. In this case, however, we are using a prepared
- // statement to avoid malicious data from affecting
- // the query.
- $stmt = $mysqli->prepare($sql);
- if ($stmt === false) {
- die('Could not prepare SQL: '.$mysqli->error);
- }
- // Bind some variables to the statement
- // The bound variables here ($vLicense, $dLicense, etc.) are
- // defined here and bound to this statement. We are setting
- // the *values* of these variables further down.
- $ok = $stmt->bind_param('sssi', $vLicense, $dLicense, $arrived, $charge);
- if ($ok === false) {
- die('Could not bind params: '.$stmt->error);
- }
- // Set the values of the bound variables here:
- $vLicense = filter_input(INPUT_POST, 'V_License_No', FILTER_SANITIZE_STRING);
- $dLicense = filter_input(INPUT_POST, 'D_License_No', FILTER_SANITIZE_STRING);
- $arrived = date('H:i');
- if (isset($_POST['vehicle_type']) && $_POST['vehicle_type'] === 'four_wheel') {
- $charge = 50;
- } else {
- $charge = 400;
- }
- // Execute the query
- if ($stmt->execute() === false) {
- die('Could not execute query: '.$stmt->error);
- } else {
- echo '<p>Query executed successfully!</p>';
- }
Advertisement
Add Comment
Please, Sign In to add comment