php - Populating '<select>' Dynamically and Retrieving Seleceted Value -
hello populated drop down list data database, want retrieve selected value , echo itz not working, keeps on coming empty.
<select> <option value="0">--none selected--</option> <?php $dbhost = 'localhost'; $dbuser = 'phil'; $dbpass = '********'; // fetching usergroupid int textbox $conn = mysql_connect($dbhost, $dbuser, $dbpass); $sql = "select * usergroups"; mysql_select_db('dopetunez'); $result = mysql_query($sql); // while row of data exists, put row in $row associative array // note: if you're expecting 1 row, no need use loop // note: if put extract($row); inside following loop, you'll // create $userid, $fullname, , $userstatus while ($row = mysql_fetch_assoc($result)){ ?> <option value="<?php echo $row["usergroupid"] ?>"> <?php echo $row["usergroup"]?> </option> <?php } ?> </select>
at first glance .. should select db before executing query .. replace
$sql = "select * usergroups"; mysql_select_db('dopetunez'); with
mysql_select_db('dopetunez'); $sql = "select * usergroups"; suggestion please use mysqli_ , pdo . mysql_ no longer maintained
Comments
Post a Comment