TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mohammed Adamu
NA
107
48.3k
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
Reply
Answers (
1
)
taking information from database and display on textbox
check if a user email is exist in database if user