Jump to content

Recommended Posts

Hello,

 

I have a drop down menu, and I wish to know how to get the value selected in the drop down (made with HTML & CSS) into a PHP variable.

Here is how it looks like:

<html>
<body>
<form name="myform" action="" method="">
<div align="center">
<select name="mydropdown">
<option value="1h">1 Hour</option>
<option value="3h">3 Hours</option>
<option value="12h">12 Hours</option>
<option value="1d">1 Day</option>
<option value="3d">3 Days</option>
<option value="1w">1 Week</option>
<option value="2w">2 Weeks</option>
<option value="3w">3 Weeks</option>
<option value="1m">1 Month</option>
</select>
</div>
</form>
</body>
</html>

Then it should be get when this PHP button is pressed:

echo('<input type="submit" name="test" value="Hello My Name is Bob"/>');

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/283511-get-drop-down-value-of-html-in-php/
Share on other sites

As you haven't set the forms submit mehtod (method="")

<form name="myform" action="" method="">

and you have named your drop down menu as mydropdown

<select name="mydropdown"> 

When the form has been submitted, then you'll get the selected value using $_GET['mydropdown']. If you set the forms submit method to post (method="post") you'd use $_POST['mydropdown']

Edited by Ch0cu3r

Yep, thanks, it worked with $_POST.

Alos, I might have to ask another question, it's here:

$test1 = 1;
$test2 = 1;
if ($ip == $test1 || $test2)
{
?>
        <br><input type="submit" value="Click test" />
<?php
}
echo "IP: $ip";
?>

The problem is with: if ($ip == $test1 || $test2) (that is not normal since my IP is not '1' or '1'), I can see the button, but with: if ($ip == $test1) I can (that should be normal since my IP is not 1).

ThankS.

Edited by RaJiska

Yep, thanks, it worked with $_POST.

Alos, I might have to ask another question, it's here:

$test1 = 1;
$test2 = 1;
if ($ip == $test1 || $test2)
{
?>
        <br><input type="submit" value="Click test" />
<?php
}
echo "IP: $ip";
?>

The problem is with: if ($ip == $test1 || $test2) (that is not normal since my IP is not '1' or '1'), I can see the button, but with: if ($ip == $test1) I can (that should be normal since my IP is not 1).

 

ThankS.

 

Try this

if ($ip == $test1 || $ip == $test2)

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.