hya im trying to populate a drop down select list from the database i have set the database up and written the following out if anyone can help would be much appreicated

// Fetch user details
$userdata       = mysql_query("select * from user where user_id = '".$_SESSION['userid']."' ");
$fetch_user     = mysql_fetch_array($userdata);
$user_country   = $fetch_user['user_country'];
$user_towns = $fetch_towns['user_towns'];

$userinfo       = mysql_query("select * from user_info where user_id = '".$fetch_user['user_id']."' ");
$fetch_info     = mysql_fetch_array($userinfo);
$fetch_towns            = mysql_query("select * from towns where town_id = '".$fetch_towns['town_id']."' "); ITS THIS LINE TO QUERY

The following is the but to populate from

<?php
                    $towns = mysql_query("select * from towns where town_id = '".$user_town."' order by name asc");
                ?>
                  <select name="town" id="town" class="list_drop">
                    <option value="" selected="selected">Select</option>
                    <?php while($row = mysql_fetch_array($state)) { ?>
                    <option value="<?php echo $row['name']?>" <?php if($fetch_towns['town']==stripslashes($row['name'])) echo "selected";?> >
                    <?php echo $row['name']?>
                    </option>
                    <?php } ?>
                  </select>

Heres database table missing the inserted data

CREATE TABLE IF NOT EXISTS `towns` (
  `town_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `town` varchar(50) NOT NULL,
  PRIMARY KEY (`town_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=993 ;

Your code should populate correctly, Just that I saw this line while($row = mysql_fetch_array($state)) where $state is probably not defined.

how do i define thats hun x

First of all, the functions of mysql_* is depreciated, please use mysqli or pdo. Then, through your code, you assign the result of sql into $towns = mysql_query("select * from towns where town_id = '".$user_town."' order by name asc"); therefore, the code for while($row = mysql_fetch_array($state)) should be changed to $town of your database result.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.