Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. <?php
  2. require("connect.php");
  3. if(!empty($_POST))
  4. {
  5.     $user = $_SESSION['user'];
  6.   $username = $user['username'];
  7.   $query = "
  8.  SELECT `client_id` FROM `users`
  9.  WHERE `username` = '$username' LIMIT 1
  10.  ";
  11.  
  12.   try
  13.     {
  14.  
  15.         $stmt = $db->prepare($query);
  16.         $stmt->execute();
  17.     }
  18.     catch(PDOException $ex)
  19.     {
  20.         die("Failed to run query: " . $ex->getMessage());
  21.     }
  22.  
  23.  
  24.   $rows = $stmt->fetchAll();
  25.  
  26.  
  27.   $client_id = $rows[0]['client_id'];
  28.  
  29.  
  30.  
  31. $query = "
  32.    INSERT INTO reservations (
  33.      client_id,
  34.      fname,
  35.      lname,
  36.      date,
  37.      table_id
  38.    ) VALUES (
  39.      :client_id,
  40.      :fname,
  41.      :lname,
  42.      :date,
  43.      :table_id
  44.      )";
  45.  
  46. $query_params = array(
  47.       ':client_id' => $client_id,
  48.       ':fname' => $_POST['name'],
  49.       ':lname' => $_POST['surname'],
  50.       ':date' => $_GET['date'],
  51.       ':table_id' => $_GET['id']
  52.     );
  53.  
  54.     try
  55.     {
  56.         // Execute the query to create the user
  57.         $stmt = $db->prepare($query);
  58.         $result = $stmt->execute($query_params);
  59.     }
  60.     catch(PDOException $ex)
  61.     {
  62.         // Note: On a production website, you should not output $ex->getMessage().
  63.         // It may provide an attacker with helpful information about your code.
  64.         die("Failed to run query: " . $ex->getMessage());
  65.     }
  66. }
  67. ?>
  68.  
  69.  
  70.  
  71.  
  72.  
  73. <!DOCTYPE html>
  74.  
  75. <html>
  76. <head>
  77. </head>
  78. <body>
  79.  
  80. <form action="make_reserv.php<?php echo "?id=" . $_GET['id'] . "&date=" . $_GET['date']; ?>" method="post">
  81.   Όνομα : <input type="text" name="name"> </br>
  82.   Επώνυμο : <input type="text" name="surname"> </br>
  83.  
  84.   <input type="submit" name="submit">
  85. </form>
  86. </body>
  87. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement