Jump to content

Archived

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

shibbi3

select menu and php

Recommended Posts

hi everyone,

I am having trouble integrating the select menu and php. I am not sure how to access the selected value

Can anyone tell me what is wrong with this code?

[code]
<form method="post" action="test.php" enctype="multipart/form-data">
    <select name="about">
    <option selected="selected">General</option>
    <option>Lures</option>
    <option>Sales</option>
    <option>Other</option>
    </select>
</form>

<?php

          $selected = $_POST['about'];
            echo $selected;
?>
[/code]

shouldnt that echo the selected value?

Share this post


Link to post
Share on other sites
You're not submitting the form!

Try this:
[code]
<form method="post" action="test.php" enctype="multipart/form-data">
    <select name="about">
    <option selected="selected">General</option>
    <option>Lures</option>
    <option>Sales</option>
    <option>Other</option>
    </select>
  <input type="submit" name="submit" value="submit">
</form>

<?php

          $selected = $_POST['about'];
            echo $selected;
?>
[/code]

Regards
Huggie

Share this post


Link to post
Share on other sites
In PHP, you need to send the information to the server (by clicking submit for example) and then the server can output/do what ever you want.

So, you need to have the form (in form.htm for example):
[code]<form method="post" action="test.php" enctype="multipart/form-data">
   <select name="about">
   <option selected="selected">General</option>
   <option>Lures</option>
   <option>Sales</option>
   <option>Other</option>
   </select>
<input type="submit">
</form>[/code]

And then the output comes from test.php, the form's action:
[code]<?php

          $selected = $_POST['about'];
            echo $selected;
?>[/code]


You need PHP to be installed on your server of course...

Hope it helps,
Orio.

Share this post


Link to post
Share on other sites
Is this what you need


<form method="post" action="" enctype="multipart/form-data">
    <select name="about">
    <option selected="selected">General</option>
    <option>Lures</option>
    <option>Sales</option>
    <option>Other</option>
  [color=red]<input type="submit" value="Go" name="submit">[/color]
    </select>
</form>

<?php

    $selected = $_POST['about'];
    echo $selected;
?>

Share this post


Link to post
Share on other sites
THANK YOU!!!!!!

I needed both the submit button and the values for the select menu for it to work.

was a silly mistake :S

THANK YOU AGAIN!!!!!

Share this post


Link to post
Share on other sites

×

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.