Day 3 on this and I’m no closer than when I started. I have a db with various fields. One of them is fname. I’m trying to populate a Select box’s options with it. A daunting task if there ever was one! Here is my code:
[code=php]
<form method=”post” action=”<?php echo htmlentities($_SERVER[‘PHP_SELF’]);?>”>
<select name=”view”>
<?php
require_once ‘root_login.php’;
try{
$stmt = $db->prepare(“SELECT fname FROM attendees”);
$stmt->execute();
$result = $stmt->fetchAll();
foreach($result as $row) { ?>
<option value=”<?php echo $row[‘fname’]; ?>”><?php echo $row[‘fname’]; ?></option>
<?php }
catch (PDOException $ex){
/*** if we are here, something has gone wrong with the database ***/
echo ‘We are unable to process your request. Please try again later’;
}
?>
</select>
<input type=”submit” value=”Go”>
</form>
Here is root_login.php:
[code=php]
<?php
$db = new PDO(‘mysql:host=localhost;dbname=myDB’, ‘adminUsername’, ‘myPW’);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
?>
I get no errors. What I do get is an empty Select box and the button. Not one field value gets put in the Select box. If you know how to do this, will you please show me [B]how