Jump to content

[SOLVED] trouble generating dropdown from mysql


aebstract

Recommended Posts

Alright, I am generating content for a drop down based on the information that I have stored in a database. It is very basic information, it is a table with "id", "plantloc", "password", and "address". What I want to do is generate a drop down that contains every plant. It should reference by id and should display as "plantloc". The plantloc is a nice looking description of the location, this way the user chooses their location and continues to login.

 

Here is what I have:

 

<?php
mysql_connect("localhost","berryequipment","gU8Kso8Y") or die(mysql_error());
mysql_select_db("berryequipment_net");
$result = mysql_query("SELECT * FROM plants ORDER BY plantloc ASC") or DIE(mysql_error());

$options="";

while ($row=mysql_fetch_array($result)) {

$id=$r["id"];
$plantloc=$r["plantloc"];
    $options .= "<OPTION VALUE=\"$id\">".$plantloc;
} 

?>



<form action="account.php?menu=login" method="post">
   plant loc<br />

<SELECT NAME=dropdown>
<OPTION VALUE=0>
<?=$options?>
</SELECT>
<br /><br />
   password <br />
   <input type="password" maxlength="6" class="textfield" name="password" size="6" /><br /><br />
   <input type="submit" name="submit" class="textfield" value="login" />


</form>

Link to comment
Share on other sites

Alright try this on for size

 

<?php
if(mysql_connect("localhost","berryequipment","gU8Kso8Y")) {
	if(mysql_select_db("berryequipment_net")) {
		$query = mysql_query("SELECT * FROM plants ORDER BY plantloc ASC");
		$options = NULL;
		while($row = mysql_fetch_array($query)) {
			$id = $row["id"];
			$plantloc = $row["plantloc"];
			$options .= '<option value="$id">' . $plantloc . '</option>';
		} 
		print '<form action="account.php?menu=login" method="post">';
		print 'plant loc<br />';
		print '<select name=dropdown>';
		print '<option value=0>----</option>';
		foreach($options as $text) {
			print $text;
		}
		print '</select>';
		print '<br /><br />';
		ptint 'password <br />';
		print '<input type="password" maxlength="6" class="textfield" name="password" size="6" />';
		print '<br /><br />';
		print '<input type="submit" name="submit" class="textfield" value="login" />';
		print '</form>';
	}
	else {
		print mysql_error();
	}
}
else {
	print mysql_error();
}
?>

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.