Jump to content

Drop down menu input help needed


python72

Recommended Posts

I am brand new to php and I don't know where I am going wrong with this.

I would like to have drop down menu which is populated from mySQL and which would allow user to select one option.

The selection would be used on the following page once the form is submitted.

Right now I have the following script and it populates the dropdown menu but it does not return value when selection is made.

 

<form action="databaseinputcheck2.php" method="post">
<?php
mysql_connect("localhost", "xxxxxxxxxxxx", "xxxxxxxxxxxxxx") or die(mysql_error());
echo "Connected to MySQL<br />";
?>
<p>Lotteries:
<?php
mysql_select_db("wpawlowski") or die(mysql_error());
// Get all the data from the "LotteryNames" table
$lotterynameresult = mysql_query("SELECT id, Name FROM LotteryNames") 
or die(mysql_error());  
?>
<select name="LotteryName" size="1">
<option selected value="">Select One</option>
<option value="">----------</option>
<?php
// keeps getting the next row until there are no more to get
while($currentlottery = mysql_fetch_array( $lotterynameresult )) {
$lid=$currentlottery['id'];
$lname=$currentlottery['Name'];
// Print out the contents of each row into drop down menu
echo "<option value='$lid'>$lname</option>\n";
//$options.="<OPTION VALUE=\"$lid\">".$lname; //Selection input line

} 
?>
<input type="submit" value="GO" />
</form>

 

I looked on the internet and it is my understanding that if I comment out the line starting withc "echo" and uncomment the one below the drop down menu should still be populated and the selection would be stored in the $options variable which in turn  could be transfered to databaseinputcheck2.php with

$_POST to be used there, but when I do uncomment that line and comment the echo line out my drop down menu is not populated, what am I doing wrong?

 

Link to comment
Share on other sites

So if I include the following code in databaseinputcheck2.php it should display the lid value once the GO button is clicked?

 

<?php
$lid=$_POST['lid'];
echo "lid: $lid";
?>

 

Right now it does not work, is there more code I have to include to transfer this value to the next form?

Link to comment
Share on other sites

Never really read a tutorial that about those sorts of things, but the best resource around is http://www.php.net.

In all honesty your problem was somewhat HTML based.  The best advice anyone ever gave me when I started to learn php was to echo variables all the time when debugging to make sure they are what you are expecting them to be.

 

Oh and make sure to mark your problem solved. (A button on the bottom left hand of this screen)

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.