Pear Quickforms Select Element from Mysql Query

Hi,

I’m trying build a form using Quickforms that includes some select elements with information pulled from a Mysql table. I know the data needs to be an array. And I think I’ve done that based on testing the outcome of the query. My problem is coming in filling the dropdown box with the results. The element and drop down display, but there isn’t anything in the dropdown. I’ve been searching around all night to try to configure it, but have had no luck. Following is the code I’m using. Any input would be greatly appreciated. Thank you in advance.

<?php

require_once 'HTML/QuickForm.php';
require_once 'dbcred.php';

$db = new PDO($dsn, $user, $password);
$db->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
//sql query//
try 
{
$sql = 'SELECT cid, qb_name from qb';
$stmt = $db->prepare($sql);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
//I think the problem is here, although I get this to display properly as an array//
{
  echo $row['qb_name'];
} 
}
for ($i = 0; $i < count($result); $i++) {
  $row = $result[$i];
  echo $row['qb_name'];
} 
}
catch (PDOException $e)
{
throw new SignUpDatabaseException('Error with database query'.$e->getMessage());
}
//build the form.//
$form = new HTML_QuickForm('regForm', 'POST', 'output.php');
// The email field
$form->addElement('text', 'email', 'Email Address');
$form->addRule('email', 'Please enter an email address',
'required', FALSE, 'client');
$form->addRule('email', 'Please enter a valid email address',
'email', FALSE, 'client');
$form->addElement('checkbox', 'termsagree', 'I agree with the TERMS AND CONDITIONS', 
'AGREE (by checking this box, you agree to the terms and conditions <br>governing this website and service.) 
<a href="termsandconditions.php" target="_blank"> Terms and Conditions</a> (Please click to read)');
$form->addRule('termsagree', 'You must agree to the terms and conditions by checking off the agree box', 'required', FALSE, 'client');
$form->addElement('hidden', 'userName', '' . $curUser . '');
$form->addElement('hidden', 'league_id', '3');
$form->addElement('hidden', 'league_name', 'Sample Football League');
$form->addElement('select', 'qb_name', 'Quaterback', $row->qb_name ); //not sure if this is correct either.  Is the last variable in the correct form?//
$form->addElement('submit', 'submit', 'Register');

if ($form->validate())
{
$submitVars = array(
'email' => $form->getSubmitValue('email'),
'termsagree' => $form->getSubmitValue('termsagree'),
'league_id' => $form->getSubmitValue('league_id'),
'league_name' => $form->getSubmitValue('league_name'),
'userName' => $form->getSubmitValue('userName'),
'qb_name' => $form->getSubmitValue('qb_name'),
);
}

print $form->toHtml()

?>

Yeah, I was screwing with that section all night. That was one of the last things I tried from some info posted on another thread. There was a $result in there at one point.

The only thing I notice is that you are using the variable $result in your loop. $result was not been given a value, so the loop will not run.

for ($i = 0; $i < count($result); $i++) {

$row = $result[$i];

echo $row[‘qb_name’];

}