DirtySnipe Posted August 15, 2012 Share Posted August 15, 2012 I have a php file which contains a html form. Within the html form are multiple drop down boxes which are supposed to pull information from a mysql database. What im also trying to do is get it to show a default entry from the database. <select style="width:100px" name="person_involved"> <?php mysql_connect("localhost", "username", "password") or die("Connection Failed"); mysql_select_db("mydatabase") or die("Connection Failed"); $sql = "SELECT * FROM hesk_location ORDER BY name ASC"; $result = hesk_dbQuery($sql); while ($row=hesk_dbFetchAssoc($result)) { $sel = $row['isDefault'] == true ? "selected='selected'" : ""; ?> <option <?=$sel?> value="<?=$row['name']?>"><?=$row['name']?></option> <?php } ?> </select> but for some reason it only displays Value=""> not the values from the database.. can anyone help me out here? Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 15, 2012 Share Posted August 15, 2012 Does your server have short tags enabled? Try changing it to <option <?php echo $sel; ?> value="<?php echo $row['name']; ?>"><?php echo $row['name']; ?></option> Or for readability, don't leave PHP. echo '<option '.$sel.' value="'.$row['name'].'">'.$row['name'].'</option>'; Quote Link to comment Share on other sites More sharing options...
DirtySnipe Posted August 15, 2012 Author Share Posted August 15, 2012 Nail on the head. Thanks for that. I had installed a new webserver and forgot about the short tags. thanks again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.