Jump to content

Using DropDown menus in PHP/MYSQL form..


virtuexru

Recommended Posts

Need some help here, how do I get whatever you choose in the dropdown to output into the PHP.

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<body>
<form action="insert.php" method="post">
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>Job Title:</td>
<td><input type="text" name="title"></td>
</tr>
<tr>
<td>Job Number:</td>
<td><input type="text" name="number"></td>
</tr>
<tr>
<td>Company Description:</td>
<td><input type="text" name="description"></td>
</tr>
<tr>
<td>Category:</td>
[b] <td><select name="category" onChange="MM_jumpMenu('parent',this,0)">
<option>Infastructure</option>
<option>Development</option>
<option>BA/PM</option>
</select>
</td>[/b] </tr>
<tr>
<td>Salary:</td>
<td><input type="text" name="salary"></td>
</tr>
<tr>
<td>Additional Compensation Information:</td>
<td><input type="text" name="addcomp"></td>
</tr>
<tr>
<td>Position Type:</td>
<td><input type="text" name="position"></td>
</tr>
<tr>
<td>Location:</td>
<td><input type="text" name="location"></td>
</tr>
<tr>
<td>Job Details:</td>
<td><input type="text" name="details"></td>
</tr>
</table>
<div align="center">
<input type="Submit">
</div>
</form>
<div align="center">To see output of database, click <a href="output.php">Here</a></div>
</body>[/quote]

into the output which is here:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?
$user="****";
$password="****";
$database="****";

mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM joborder";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<b><center>Database Output</center></b><br><br>";
?>

<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Job Title:</font></th>
<th><font face="Arial, Helvetica, sans-serif">Job Number:</font></th>
<th><font face="Arial, Helvetica, sans-serif">Company Description:</font></th>
<th><font face="Arial, Helvetica, sans-serif">Category:</font></th>
<th><font face="Arial, Helvetica, sans-serif">Salary:</font></th>
<th><font face="Arial, Helvetica, sans-serif">Additional Compensation Information:</font></th>
<th><font face="Arial, Helvetica, sans-serif">Position Type:</font></th>
<th><font face="Arial, Helvetica, sans-serif">Location:</font></th>
<th><font face="Arial, Helvetica, sans-serif">Job Details:</font></th>
</tr>

<?

$i=0;
while ($i < $num) {

$title=mysql_result($result,$i,"title");
$number=mysql_result($result,$i,"number");
$description=mysql_result($result,$i,"description");
$category=mysql_result($result,$i,"category");
$salary=mysql_result($result,$i,"salary");
$addcomp=mysql_result($result,$i,"addcomp");
$position=mysql_result($result,$i,"position");
$location=mysql_result($result,$i,"location");
$details=mysql_result($result,$i,"details");

?>

<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo $title; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $number; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $description; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $category; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $salary; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $addcomp; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $position; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $location; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $details; ?></font></td>
</tr>

<?

$i++;
}

echo "</table>";
[/quote]
Link to comment
Share on other sites

the jumpmenu will submit the form (or run that dreamweaver javascript) when that option is changed -- probably not what you're looking for. I'd remove the onclick="MM_" thing. Other than that, your select code looks accurate.

On the other end, the variable $_POST['category'] will have the value they selected -- just like the $_POST['title'] will be whatever they typed in the title textfield.

so [code]$query="SELECT * FROM `joborder` WHERE `category` = '".$_POST['category']."'";[/code] will query the database for all records where your category field is what they selected.

Is that what you're trying to do?
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.