Advertisement
Eline_VDB

Untitled

May 27th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.93 KB | None | 0 0
  1. <!doctype html>
  2. <head>
  3.   <meta charset="utf-8">
  4.   <link href="css/bootstrap.min.css"rel="style">
  5.   <script src="js/bootstrap.min.js"></script>
  6.   <title>Add DVD</title>
  7.  
  8. </head>
  9.  
  10. <?php
  11. require 'database.php';
  12.  
  13. if( !empty($_POST)){
  14.   $titleError = null;
  15.   $dateError = null;
  16.   $countryError = null;
  17.   $durationError = null;
  18.  
  19.   $title = $_POST['title'];
  20.   $date = $_POST['release_date'];
  21.   $country = $_POST['origin_country'];
  22.   $duration = $_POST['duration'];
  23.  
  24.   $valid = true;
  25.   if(empty($title)){
  26.     $titleError = "Please enter a title";
  27.     $valid = false;
  28.   }
  29.  
  30.   if(empty($date)){
  31.     $dateError = "Please enter a date";
  32.     $valid = false;
  33.   }
  34.  
  35.   if(empty($country)){
  36.     $counrtyError = "Please enter a country";
  37.     $valid = false;
  38.   }
  39.  
  40.   if(empty($duration)){
  41.     $durationError = "Please enter a duration";
  42.     $valid = false;
  43.   }
  44.  
  45.   if($valid){
  46.     $pdo = Database::connect();
  47.     $pdo -> setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
  48.     $sql = "INSERT INTO dvd(title,release_date, origin_country, duration) values(?,?,?,?)";
  49.     $q = $pdo->prepare($sql);
  50.     $q->execute(array($title,$date, $country, $duration));
  51.     Database::disconnect();
  52.     header("Location: dvd.php");
  53.   }
  54.  
  55.  
  56. }
  57.  
  58.  
  59. ?>
  60.  
  61.  
  62. <body>
  63.  
  64. <div class="container">
  65.   <div class="span10 offset1">
  66.     <div class="row">
  67.       <h3>Add a new DVD</h3>
  68.     </div>
  69.  
  70. <!-- voeg een dvd toe -->
  71. <!-- title -->
  72.   <form class="form-horizontal" action="createdvd.php" method="post">
  73.     <div class="control-group <?php echo !empty($titleError)?'error':'';?>">
  74.     <label class="control-label">Title</label>
  75.     <div class="controls">
  76.     <input name="title" type="text" placeholder="title" value="<?php echo !empty($titleError)):?>"></input>
  77.     <span class="help-inline"><?php echo $titleError;?></span>
  78.     <?php endif; ?>
  79.     </div>
  80.   </div>
  81.  
  82.     <!--
  83.     <label>Description</label>
  84.     <input name="description"type="textarea"placeholder="put here a description"></input>
  85.   -->
  86. <!-- release date -->
  87. <form class="form-horizontal" action="createdvd.php" method="post">
  88.   <div class="control-group <?php echo !empty($dateError)?'error':'';?>">
  89. <label class="control-label">Release_date</label>
  90. <div class="controls">
  91. <input name= "releasedate" type="text"placeholder="ex. 01/01/1990" value="<?php echo !empty($dateError)):?>"></input>
  92. <span class="help-inline"><?php echo $dateError;?></span>
  93. <?php endif; ?>
  94. </div>
  95. </div>
  96.  
  97. <!-- origin country -->
  98. <form class="form-horizontal" action="createdvd.php" method="post">
  99.   <div class="control-group <?php echo !empty($countryError)?'error':'';?>">
  100. <label>Origin country</label>
  101. <div class="controls">
  102. <input name="origin-country"type="text" placeholder="origin country" value="<?php echo !empty($countryError)):?>"></input>
  103. <span class="help-inline"><?php echo $countryError;?></span>
  104. <?php endif; ?>
  105. </div>
  106. </div>
  107.  
  108. <!-- duration -->
  109. <form class="form-horizontal" action="createdvd.php" method="post">
  110.   <div class="control-group <?php echo !empty($durationError)?'error':'';?>">
  111. <label>Duration</label>
  112. <div class="controls">
  113. <input name="duration"type="text"placeholder="ex 120"value="<?php echo !empty($durationError)):?>"></input>
  114. <span class="help-inline"><?php echo $durationError;?></span>
  115. <?php endif; ?>
  116. </div>
  117. </div>
  118.  
  119.  
  120. <!-- genre
  121. <label>Genre</label>
  122. <input name="genre1"type="checkbox">Action</input>
  123. <input name="genre2"type="checkbox">Adventure</input>
  124. <input name="genre3"type="checkbox">Comedy</input>
  125. <input name="genre4"type="checkbox">Drama</input>
  126. <input name="genre5"type="checkbox">Fantasy</input>
  127. <input name="genre6"type="checkbox">Horror</input>
  128. <input name="genre7"type="checkbox">Romantic</input>
  129. <input name="genre8"type="checkbox">Science Fiction</input>
  130. -->
  131.  
  132. <div class="form-actions">
  133.     <button type="submit" class="btn btn-success">Create</button>
  134.     <a class="btn" href="dvd.php">Back</a>
  135.     </div>
  136.  
  137. </form>
  138.  
  139. </div>
  140.  
  141.  
  142. </body>
  143.  
  144. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement