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>

Add a submit button to you form. When user clicks it, it will post the selected project_name to hourssubmit.php where you can access it with $_POST['project_name']

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.