Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('../../../connect.php');
- // dropdown
- $fruit_type = '';
- $sql = "SELECT fruit_id, FruitType from mydb.mytbl";
- $stmt = $dbh->prepare($sql);
- $stmt->execute();
- $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
- foreach ($results as $row) {
- $fruit_type.= '<option value="' . $row["fruit_id"] . '">' . $row["FruitType"] . '</option>';
- }
- if(isset($_POST['submit'])){
- $errors = array();
- require('validate.php');
- if(!count($errors)){
- $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
- $sql = "INSERT INTO fruittable
- (fruit_id)
- VALUES ('".$row['fruit_id']."');
- ";
- $stmt = $dbh->prepare($sql);
- $result = $stmt->execute();
- }
- }
- if(isset($result)){
- if($result){
- }else{
- echo '<b>Unable to Insert</b>';
- print '<pre>'.print_r($stmt->errorInfo(), true);
- }
- }
- ?>
- <h1>Log Fruit</h1>
- <form method="post" action="add.php">
- fruit type <br/>
- <select name="fruit_select">
- <option value=""</option>
- <?php echo $fruit_type;?> <br/>
- </select>
- <p></p>
- <br/>
- <input type="submit" name="submit" value="Add" />
- </form>
- <?php
- require_once('../../../connect.php');
- if ($_POST['submit']) {
- $fruitid=$_POST['fruit_select'];
- $insertsql = "INSERT INTO fruittable (fruit_id) VALUES (:fruitid)";
- $stmt = $dbh->prepare($insertsql);
- $stmt->bindParam(':fruitid', $fruitid);
- $stmt->execute();
- }
- $fruit_type = '';
- $sql = "SELECT fruit_id, FruitType FROM table";
- $stmt = $dbh->prepare($sql);
- $stmt->execute();
- ?>
- <h1>Log Fruit</h1>
- <form method="post" action="add.php">
- fruit type <br/>
- <select name="fruit_select">
- <option value=""</option>
- <?php
- while ($row = $stmt->fetch()) {
- echo "<option value='".$row['fruit_id']."'>".$row['FruitType']."</option>";
- }
- ?>
- </select>
- <br/>
- <input type="submit" name="submit" value="Add" />
- </form>
- <option value=""</option>
- <option value="" /></option>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement