Jump to content


Photo

Using DropDown menus in PHP/MYSQL form..


  • Please log in to reply
4 replies to this topic

#1 virtuexru

virtuexru
  • Members
  • PipPipPip
  • Advanced Member
  • 200 posts

Posted 22 May 2006 - 08:20 PM

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>
<td><select name="category" onChange="MM_jumpMenu('parent',this,0)">
<option>Infastructure</option>
<option>Development</option>
<option>BA/PM</option>
</select>
</td>
</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]

#2 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 22 May 2006 - 08:24 PM

what's the jumpmenu for?

#3 virtuexru

virtuexru
  • Members
  • PipPipPip
  • Advanced Member
  • 200 posts

Posted 22 May 2006 - 08:26 PM

It allows the user to only select 3 options for that certain field. I then what whatever they select to go into the database under the category field.

#4 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 22 May 2006 - 08:32 PM

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
$query="SELECT * FROM `joborder` WHERE `category` = '".$_POST['category']."'";
will query the database for all records where your category field is what they selected.

Is that what you're trying to do?

#5 virtuexru

virtuexru
  • Members
  • PipPipPip
  • Advanced Member
  • 200 posts

Posted 22 May 2006 - 08:46 PM

Ah, yea amazing. I took out the MM_ stuff and it worked great.

Thanks a lot.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users