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? Link to comment https://forums.phpfreaks.com/topic/267118-problems-with-getting-value-from-mysql-database-using-php-and-html-dropdown-box/ 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>'; Link to comment https://forums.phpfreaks.com/topic/267118-problems-with-getting-value-from-mysql-database-using-php-and-html-dropdown-box/#findComment-1369584 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. Link to comment https://forums.phpfreaks.com/topic/267118-problems-with-getting-value-from-mysql-database-using-php-and-html-dropdown-box/#findComment-1369615 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.