Jump to content

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

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.