954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Auto populate php form array from database?

bah!!

At one time I knew how to manipulate mysql data and put it into and out of things - I've been staring at this all day and it still doesn't work.

Direction, help, code, etc anything is appreciated. I haven't done db scripting in about a year so please jog the old noggin. ;)


Logic.

two drop down forms and a radio selection of 4 choices.


If person selects X from first dropdown then need to show only a selected amount of choices in second dropdown

person then makes a choice in second drop down

then person chooses from 4 radio options

Result is building a URL based on values selected from drop down #1, #2 & radio values.

the URL is then included on a "results" page.

rough code, that doesn't have the arrays or any code to autopopulate dropdown #2 based on what is chosen for dropdown#1

<?php require_once('Connections/db.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form action="index_results.php" method="POST" name="index" id="index">
<?php
$db_selected = mysql_select_db( $database_dnrdb, $dnrdb);
if (!$db_selected) {
   die ('Can\'t use' . $database_dnrdb .' : ' . mysql_error());
}

$query = sprintf("SELECT ID, DIV, WHAT, AGE, NAME FROM dtindex");

// Perform Query
$result = mysql_query($query);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
   $message  = 'Invalid query: ' . mysql_error() . "\n";
   $message .= 'Whole query: ' . $query;
   die($message);
}

// Use result
while ($row = mysql_fetch_assoc($result)) {
 
   echo '<Select name="division">';
   echo '<option value="' . $row['DIV'] .'">' . $row['WHAT'] .'</option>';
   echo '</select><br clear="all" />'. "\n\n";
}
// Use result
while ($row = mysql_fetch_assoc($result)) {
 
   echo '<Select name="who">';
   echo '<option value="' . $row['AGE'] .'">' . $row['NAME'] .'</option>';
   echo '</select><br clear="all" />'. "\n\n";
}
mysql_free_result($result);
?>
<input type="radio" name="pet" value="horse" />horse</form>
<input type="radio" name="pet" value="dogs" />dogs</form>
<input type="radio" name="pet" value="cats" />cats</form>
<input name="Submit" type="submit" />

</form>

</body>
</html>

INDEX RESULTS

<?php include ('. $division . $who . $pet .''.html'); ?>

Which should result in this

<php include ('G34dog.html'); ?>

Or something to that effect.

I would like to include the "results" in an array which then tells the second row "who" what to populate it with. I found several help areas on making a manual array but that is not an option with these people. I have a database set up with the information in one table. Fields: ID, DIV, WHAT, AGE, NAME

Depending on the "WHAT" they choose is what "NAME" shows up in the option list. however the real alphanumeric value assignments to build the URL are DIV and AGE.

I've tried so many different things today and I still get a blank page. Not even an error to say something is broken.

So frustrated.
Jade

JadeaDragon
Newbie Poster
8 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You