Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. <?php
  2.  
  3. require_once('../../../connect.php');
  4.  
  5.  
  6. // dropdown
  7. $fruit_type = '';
  8. $sql = "SELECT fruit_id, FruitType from mydb.mytbl";
  9. $stmt = $dbh->prepare($sql);
  10. $stmt->execute();
  11. $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
  12. foreach ($results as $row) {
  13. $fruit_type.= '<option value="' . $row["fruit_id"] . '">' . $row["FruitType"] . '</option>';
  14.  
  15. }
  16.  
  17.  
  18.  
  19. if(isset($_POST['submit'])){
  20.  
  21.  
  22.  
  23. $errors = array();
  24. require('validate.php');
  25.  
  26.  
  27.  
  28. if(!count($errors)){
  29.  
  30. $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
  31.  
  32. $sql = "INSERT INTO fruittable
  33. (fruit_id)
  34. VALUES ('".$row['fruit_id']."');
  35. ";
  36.  
  37. $stmt = $dbh->prepare($sql);
  38. $result = $stmt->execute();
  39.  
  40. }
  41.  
  42. }
  43.  
  44.  
  45.  
  46. if(isset($result)){
  47. if($result){
  48.  
  49. }else{
  50. echo '<b>Unable to Insert</b>';
  51. print '<pre>'.print_r($stmt->errorInfo(), true);
  52. }
  53. }
  54.  
  55.  
  56. ?>
  57.  
  58. <h1>Log Fruit</h1>
  59. <form method="post" action="add.php">
  60.  
  61. fruit type <br/>
  62. <select name="fruit_select">
  63. <option value=""</option>
  64. <?php echo $fruit_type;?> <br/>
  65. </select>
  66. <p></p>
  67.  
  68.  
  69.  
  70. <br/>
  71. <input type="submit" name="submit" value="Add" />
  72.  
  73. </form>
  74.  
  75. <?php
  76. require_once('../../../connect.php');
  77.  
  78. if ($_POST['submit']) {
  79. $fruitid=$_POST['fruit_select'];
  80. $insertsql = "INSERT INTO fruittable (fruit_id) VALUES (:fruitid)";
  81. $stmt = $dbh->prepare($insertsql);
  82. $stmt->bindParam(':fruitid', $fruitid);
  83. $stmt->execute();
  84. }
  85.  
  86. $fruit_type = '';
  87. $sql = "SELECT fruit_id, FruitType FROM table";
  88. $stmt = $dbh->prepare($sql);
  89. $stmt->execute();
  90. ?>
  91.  
  92. <h1>Log Fruit</h1>
  93. <form method="post" action="add.php">
  94. fruit type <br/>
  95. <select name="fruit_select">
  96. <option value=""</option>
  97. <?php
  98. while ($row = $stmt->fetch()) {
  99. echo "<option value='".$row['fruit_id']."'>".$row['FruitType']."</option>";
  100. }
  101. ?>
  102. </select>
  103. <br/>
  104. <input type="submit" name="submit" value="Add" />
  105.  
  106. </form>
  107.  
  108. <option value=""</option>
  109. <option value="" /></option>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement