Jump to content

select menu and php


shibbi3

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?
Link to comment
https://forums.phpfreaks.com/topic/24444-select-menu-and-php/
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
Link to comment
https://forums.phpfreaks.com/topic/24444-select-menu-and-php/#findComment-111283
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.
Link to comment
https://forums.phpfreaks.com/topic/24444-select-menu-and-php/#findComment-111287
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;
?>
Link to comment
https://forums.phpfreaks.com/topic/24444-select-menu-and-php/#findComment-111288
Share on other sites

Archived

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

×
×
  • 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.