Advertisement
Eline_VDB

Untitled

Jun 11th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.61 KB | None | 0 0
  1. <!--
  2.   - maak een dropdown van dvd's
  3.   - maak een dropdown van klant
  4.   - datum is vrij invoerveld
  5.  
  6.   https://www.phpro.org/tutorials/Dropdown-Select-With-PHP-and-MySQL.html
  7.  
  8.   http://thisinterestsme.com/populate-dropdown-list-mysql/
  9.  
  10. -->
  11.  
  12. <!doctype html>
  13. <head>
  14.   <meta charset="utf-8">
  15.   <link href="css/bootstrap.min.css"rel="stylesheet">
  16.   <script src="js/bootstrap.min.js"></script>
  17.   <title>Add an order</title>
  18.  
  19. </head>
  20.  
  21. <?php
  22. error_reporting(E_ALL);
  23. ini_set('display_errors', 'On');
  24.  
  25.  
  26. require 'database.php';
  27.  
  28. if( !empty($_POST)){
  29.   $clientError = null;
  30.   //$dvdError = null;
  31.   //$dateError = null;
  32.  
  33.  
  34.   $client = $_POST['client'];
  35.   //$dvd = $_POST['dvd'];
  36.   //$date = $_POST['date'];
  37.  
  38.  
  39.   $valid = true;
  40.   if(empty($client)){
  41.     $titleError = "Please select a client";
  42.     $valid = false;
  43.   }
  44.  
  45. //  if(empty($dvd)){
  46. //    $descriptionError = "Please select a dvd";
  47. //    $valid = false;
  48. //  }
  49. //
  50. //  if(empty($date)){
  51. //    $dateError = "Please enter a date";
  52. //    $valid = false;
  53. //
  54.  
  55.  
  56.   if($valid){
  57.     $pdo = Database::connect();
  58.     $pdo -> setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
  59.     $sql = "INSERT INTO tl_order(client_id, dvd_id, start_date) values(?,?,?)";
  60.     $q = $pdo->prepare($sql);
  61.     $q->execute(array($client));
  62.     Database::disconnect();
  63.     header("Location: order.php");
  64.   }
  65.  
  66. }
  67.  
  68.  
  69. ?>
  70.  
  71.  
  72. <body>
  73.  
  74. <div class="container">
  75.   <div class="span10 offset1">
  76.     <div class="row">
  77.       <h3>Add a new order</h3>
  78.     </div>
  79.  
  80.  
  81. <!-- selecteer de klant -->
  82. <form class="form-horizontal" action="createorder.php" method="post">
  83.   <div class="control-group <?php echo !empty($clientError)?'error': '';?>">
  84.   <label class="control-label">Client</label>
  85.   <div class="controls">
  86.   <select name="client" class="form-control"value="<?php echo !empty($client)?$client:'';?>" >
  87.     <option selected disabled>Select a client</option>
  88.     <?php
  89.       include 'database.php';
  90.       $pdo = Database::connect();
  91.       $sql = 'SELECT id, CONCAT(tl_client.first_name," ", tl_client.last_name) AS "full_name" FROM tl_client';
  92.       ?>
  93.     <?php foreach($pdo -> query($sql) as $row){
  94.       echo '<option value="'. $row['id'] .'">' . $row['full_name'] . '</option>'
  95.       }
  96.  
  97.         ?>
  98.   </select>
  99.   <?php if (!empty($clientError)): ?>
  100.   <span class="help-inline"><?php echo $clientError;?></span>
  101.   <?php endif; ?>
  102.  
  103. </div>
  104. </div>
  105.  
  106.  
  107.   <div class="form-actions">
  108.       <button type="submit" class="btn btn-success">Create</button>
  109.       <a class="btn" href="order.php">Back</a>
  110.       </div>
  111.  
  112.   </form>
  113.  
  114.   </div>
  115.  
  116.   </div>
  117.  
  118.  
  119.   </body>
  120.  
  121.   </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement