Jump to content


Photo

select menu and php


  • Please log in to reply
4 replies to this topic

#1 shibbi3

shibbi3
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 19 October 2006 - 02:15 PM

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?

<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;
?>

shouldnt that echo the selected value?

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 19 October 2006 - 02:21 PM

You're not submitting the form!

Try this:
<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;
?>

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 19 October 2006 - 02:23 PM

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):
<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>

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

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


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

Hope it helps,
Orio.
Think you're smarty?

(Gone until 20 to November)

#4 stb74

stb74
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts
  • LocationNorthern Ireland

Posted 19 October 2006 - 02:23 PM

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>
  <input type="submit" value="Go" name="submit">
    </select>
</form>

<?php

    $selected = $_POST['about'];
    echo $selected;
?>
nifootball.co.uk

#5 shibbi3

shibbi3
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 19 October 2006 - 02:25 PM

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!!!!!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users