Guest User

Untitled

a guest
Sep 14th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.72 KB | None | 0 0
  1. <?php
  2.  
  3. // Create database handle
  4. $mysqli = new MySQLi('localhost', 'root', '11111', 'CAR_PARKING_SYSTEM');
  5.  
  6. // The SQL that we will use; the question marks are
  7. // placeholders for where the values will be placed
  8. $sql = <<< SQL
  9.     INSERT INTO `CUSTOMER_VEHICLE` (
  10.         `V_License_No`,
  11.         `D_License_No`,
  12.         `Arrived_Time`,
  13.         `Charge`
  14.     ) VALUES (
  15.         ?, ?, ?, ?
  16.     );
  17. SQL;
  18.  
  19. // Prepare the SQL and get a statement handle
  20. // Prepared queries are send to the database, which
  21. // checks it for errors and also optimizes it so that
  22. // consecutive calls to `execute()` are performed
  23. // faster. In this case, however, we are using a prepared
  24. // statement to avoid malicious data from affecting
  25. // the query.
  26. $stmt = $mysqli->prepare($sql);
  27. if ($stmt === false) {
  28.     die('Could not prepare SQL: '.$mysqli->error);
  29. }
  30. // Bind some variables to the statement
  31. // The bound variables here ($vLicense, $dLicense, etc.) are
  32. // defined here and bound to this statement. We are setting
  33. // the *values* of these variables further down.
  34. $ok = $stmt->bind_param('sssi', $vLicense, $dLicense, $arrived, $charge);
  35. if ($ok === false) {
  36.     die('Could not bind params: '.$stmt->error);
  37. }
  38. // Set the values of the bound variables here:
  39. $vLicense = filter_input(INPUT_POST, 'V_License_No', FILTER_SANITIZE_STRING);
  40. $dLicense = filter_input(INPUT_POST, 'D_License_No', FILTER_SANITIZE_STRING);
  41. $arrived  = date('H:i');
  42. if (isset($_POST['vehicle_type']) && $_POST['vehicle_type'] === 'four_wheel') {
  43.     $charge = 50;
  44. } else {
  45.     $charge = 400;
  46. }
  47. // Execute the query
  48. if ($stmt->execute() === false) {
  49.     die('Could not execute query: '.$stmt->error);
  50. } else {
  51.     echo '<p>Query executed successfully!</p>';
  52. }
Advertisement
Add Comment
Please, Sign In to add comment