Jump to content

Retrieve the data from database and display it in a drop down menu and again use the same as form input in php


manjumadhav93

Recommended Posts

As a complete newbie to php and webdesigning i have a following problem.I would like to retrieve the data from database and display it in a drop down menu.Then i should allow the user to select the values from drop down list along with other details,in other words i have to embed the drop down output as the form input for the user and store the form data in another table.I am running a xampp server and i am using php 5.4 version.Please help.My code is as follows.In this case project_name is displayed as the drop down output.but how do i use the same drop down output as a input in the form.
 
 
 
<html>
<head></head>
<body>
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
include 'connect.php' ;
$tbl_name="projects";


$sql="SELECT project_name FROM $tbl_name ";

$result=mysql_query($sql);


if($result === FALSE) {
    die(mysql_error());
}
?>


<form name="resources" action="hourssubmit.php"  method="post" >

<?php
echo "<select name='project_name'>";
while ($row = mysql_fetch_array($result)) {
    
    echo "<option value='" . $row['project_name'] ."'>" . $row['project_name'] ."</option>";
}
echo "</select>";
?>

</form>
</body>
</html>

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.