Mohammed Adamu

Mohammed Adamu

  • NA
  • 107
  • 48k

how to populate data from mysql into dropdown using php

May 26 2016 11:47 AM
how to populate data from mysql into dropdown using php
 
this is my code but it only print " $cdTitle " in the list box
 
<form action="saveoffence.php" method="POST">
<select class ='text' name='offencetype'>
<?php
$server = 'localhost';
$username = 'root';
$password = '';
$database = 'database';
try{
$conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password);
} catch(PDOException $e){
die( "Connection failed: " . $e->getMessage());
}
$cdquery="SELECT offencetype from offence";
$cdresult=mysql_query($cdquery) or die ("Query to get data from firsttable failed: ".mysql_error());
while ($cdrow=mysql_fetch_array($cdresult)) {
$cdTitle=$cdrow["offencetype"];
echo "<option> $cdTitle </option>";
}
?>
</select>
<input type="text" placeholder="Enter Csae Content" required name="offence">
<input type="submit">
<div id = "footer">
<h2>[email protected]</h2></div>
</div>
</form>
 
Thanks  
 

Answers (1)