Jump to content

Problems with getting value from mysql database using php and html dropdown box


DirtySnipe

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.