Dear All help me pls..
i am unable to fetch result in dropdown from database...

connection.php

$db = new PDO("mysql:host=localhost;dbname=test","root","");

-----------------------------------------
Add_student.php

<tr> <th>City</th> <td><select name="st_city" id="st_city"> <?php echo get_option_list("city","City_id","City_name"); ?> </select> </td></tr>

-----------------------------------------
functions.php

function get_option_list($table,$id,$name)
{
$SQL=$db->query("SELECT * FROM ".$table." ORDER BY". $name);
$get_list="<option value=0>Please Select</option>";
while($row=$SQL->fetch(PDO::FETCh_ASSOC))
{

}
return $get_list;
}
Member Avatar for diafol

CONSTANTS are case-sensitive - so PDO::FETCH_ASSOC not PDO::FETCh_ASSOC

There's no code in the while loop. Do you need help on this too?

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.