Advertisement
Guest User

Untitled

a guest
Aug 17th, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. <?php
  2.  
  3. $dbhost = 'localhost';
  4.  
  5. $user = 'root';
  6.  
  7. $password = 'root';
  8.  
  9. $dbname = 'inventory';
  10.  
  11. $con = new PDO ('mysql : host = localhost; $dbname = inventory', $user, $password);
  12.  
  13.  
  14. ?>
  15. <html>
  16. <head>
  17. <title>Add to Inventory</title>
  18. </head>
  19. <body>
  20. <?php
  21. include "inventory.php";
  22.  
  23. $add = isset($_POST['add']) ? $_POST['add'] : '';
  24.  
  25. if ( $add == 'add'){
  26.  
  27. include 'inventory.php';
  28.  
  29. try {
  30.  
  31. $query = "INSERT INTO sedan SET year = ?, make = ?, model = ?, color = ?, price = ?"
  32.  
  33. $stmt=$con->prepare($query);
  34.  
  35. $stmt->bindParam(1, $_POST['year']);
  36.  
  37. $stmt->bindParam(2, $_POST['make']);
  38.  
  39. $stmt->bindParam(3, $_POST['model']);
  40.  
  41. $stmt->bindParam(4, $_POST['color']);
  42.  
  43. $stmt->bindParam(5, $_POST['price']);
  44.  
  45. $stmt->execute();
  46.  
  47. echo 'New car added';
  48.  
  49. } catch (PDOException $exception){
  50.  
  51. echo "Error: " . $exception->getMessage();
  52. }
  53.  
  54. }
  55. ?>
  56.  
  57. <form method="post" action="#">
  58.  
  59. <p>Year: <input type="text" name="year"/></p>
  60. Make: <select name="carmake">
  61. <option value="Acura">Acura</option>
  62. <option value="Audi">Audi</option>
  63. <option value="Ferrari">Ferrari</option>
  64. <option value="Infiniti">Infiniti</option>
  65. <option value="Lamborghini">Lamborghini</option>
  66. <option value="Maserati">Maserati</option>
  67. <option value="Tesla">Tesla</option>
  68. </select></p>
  69. Model: <input name="text" name="model"/>
  70. </p>
  71. Color: <select name="color">
  72. <option value="black">Midnight Black</option>
  73. <option value="blue">Clear Sky Blue</option>
  74. <option value="gray">Gunmetal Grey</option>
  75. <option value="white">Cloud White</option>
  76. <option value="yellow">Yellowjacket</option>
  77. </select></p>
  78. Price: <input type="text" name="price"/>
  79. </p>
  80. <input type="submit" value="Add to Inventory" name="submit"/>
  81. </form>
  82. </body>
  83. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement