This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 18th, 2013  |  syntax: None  |  size: 1.81 KB  |  views: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. $dbhost = 'localhost';
  4.  
  5. $user = 'root';
  6.  
  7. $password = 'root';
  8.  
  9. $dbname = 'inventory';
  10.  
  11. $pdo = new PDO("mysql:host=$dbhost; $dbname", $user, $password);
  12.  
  13.  
  14. ?>
  15.  
  16. <html>
  17. <head>
  18. <title>Add to inventory</title>
  19. </head>
  20. <body>
  21. <?php
  22.  
  23.  
  24.  
  25. if(isset($_POST['submit'])) {
  26.                                                 require_once "inventory.php";
  27.                        
  28.                         $stmt = $pdo->prepare("INSERT INTO `cars`(`year`,`make`,`model`,`color`,`price`) VALUES(:year, :make, :model, :color, :price);");
  29.                                                
  30.                         $result = $stmt->execute(array(":year" => $_POST['year'],":make" => $_POST['make'],":model" => $_POST['model'],":color" => $_POST['color'],":price" => $_POST['price']));
  31.  
  32.                         if($result) {
  33.                                 echo 'New record was saved.';
  34.                         }else{
  35.                                 echo 'Error occurred';
  36.                         }
  37.                         }
  38.  ?>
  39.  
  40. <form method="post" action="#">
  41.  
  42. <p>Year: <input type="text" name="year"/></p>
  43.  
  44. Make: <select name="make">
  45. <option value="Acura">Acura</option>
  46. <option value="Audi">Audi</option>
  47. <option value="Ferrari">Ferrari</option>
  48. <option value="Infiniti">Infiniti</option>
  49. <option value="Lamborghini">Lamborghini</option>
  50. <option value="Maserati">Maserati</option>
  51. <option value="Tesla">Tesla</option>
  52. </select></p>
  53.  
  54. Model: <input type="text" name="model"/>
  55. </p>
  56.  
  57. Color: <select name="color">
  58. <option value="black">Midnight Black</option>
  59. <option value="blue">Clear Sky Blue</option>
  60. <option value="gray">Gunmetal Grey</option>
  61. <option value="white">Cloud White</option>
  62. <option value="yellow">Yellowjacket</option>
  63.  
  64. </select></p>
  65.  
  66. Price: <input type="text" name="price"/>
  67.  
  68. </p>
  69.  
  70. <input type="submit" value="Add to Inventory" name="submit"/>
  71.  
  72. </form>
  73.  
  74. </body>
  75.  
  76. </html>
clone this paste RAW Paste Data