Advertisement
dbcalmada

dogbreeds_form_php

Jan 23rd, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.12 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors',0);
  3.  
  4. session_start();
  5.  
  6. include_once "../config.php";
  7. include_once "functions.php";
  8. include "../includes/db.php";
  9.  
  10. print printHTMLHead();
  11.  
  12. if ($_GET['mode'] == 'edit' || $_GET['mode'] == 'del') {
  13.     $sql = "select * from dogbreeds where dogbreed = '" . $_GET['dogbreed'] . "'";
  14.     $result = mysqli_query($_SESSION['dblink'],$sql);
  15.     $record = mysqli_fetch_assoc($result);
  16.     $dogbreed = $record['dogbreed'];
  17.     $description = $record['description'];
  18.     $country_code = $record['country_code'];
  19.     $price = $record['price'];
  20.     $discount_rate = $record['discount_rate'];
  21. }
  22.  
  23. switch ($_GET['mode']) {
  24.     case 'edit':
  25.         $script = 'edit_dogbreed.php';
  26.         break;
  27.     case 'del':
  28.         $script = 'del_dogbreed.php';
  29.         break;
  30.     case 'add':
  31.         $script = 'add_dogbreed.php';
  32.         break;
  33. }
  34.  
  35. ?>
  36. <form method='post' action='<?php echo $script;?>'>
  37.     <table class='dataform'>
  38.         <tr>
  39.             <td>Dog Breed:</td>
  40.             <td><input type='text' name='dogbreed' value='<?php echo $dogbreed;?>'></td>
  41.         </tr>
  42.         <tr>
  43.             <td>Description:</td>
  44.             <td><input type='text' name='description' value='<?php echo $description;?>'></td>
  45.         </tr>
  46.         <tr>
  47.             <td>Country:</td>
  48.             <td>
  49.                 <select name='country_code'>
  50.                     <option value=''>[Select Country]</option>
  51.                     <?php
  52.                         $country_sql = "SELECT * FROM countries";
  53.                         $result = mysqli_query($_SESSION['dblink'],$country_sql);
  54.                         while ($record = mysqli_fetch_assoc($result)) {
  55.                             if ($record['country_code'] == $country_code) {
  56.                                 $selected = " selected ";
  57.                             } else {
  58.                                 $selected = null;
  59.                             }
  60.                             ?><option value='<?php echo $record['country_code'];?>' <?php echo $selected;?>><?php echo $record['country'];?></option>
  61.                             <?php
  62.                         }
  63.                     ?>
  64.                 </select>
  65.             </td>
  66.         </tr>
  67.         <tr>
  68.             <td>Price:</td>
  69.             <td><input type='text' name='price' value='<?php echo $price;?>'></td>
  70.         </tr>
  71.         <tr>
  72.             <td>Discount Rate:</td>
  73.             <td><input type='text' name='discount_rate' value='<?php echo $discount_rate;?>'></td>
  74.         </tr>
  75.         <tr>
  76.             <td colspan='2'><input type='submit' value='Submit'></td>
  77.         </tr>
  78.     </table>   
  79. </form>
  80. <?php
  81.  
  82. print printFooter();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement