Jump to content

using _post


desjardins2010

Recommended Posts

hey guys

I know this is html but I'm using the php $_POST to grab the information the user chooses, i can't figure out though how to grab the info i'm looking for in this select option form

if they choose PasswordCracker v3.0 what is it i'm looking to set my $_post['']; to?

<FORM action="buy.php" method="POST">
    <select name="passwordcrakers">
      <option value="v2.0">PasswordCracker V2.0</option>
      <option value="v3.0">PasswordCracker V3.0</option>
      <option value="v4.0">PasswordCracker V4.0</option>
      <option value="v5.0">PasswordCracker V5.0</option>
      <option value="v6.0">PasswordCracker V6.0</option>
      <option value="v7.0">PasswordCracker V7.0</option>
      <option value="v8.0">PasswordCracker V8.0</option>
      <option value="v9.0">PasswordCracker V9.0</option>
      <option value="v10">PasswordCracker V10</option>
        </select><br />
	<input type="submit" value="Buy" name="submit" />
	</FORM>

Link to comment
https://forums.phpfreaks.com/topic/222742-using-_post/
Share on other sites

No, $_POST['v3.0']; is wrong, there is no field called v3.0 is there, the field is called passwordcrackers and the value would be the v3.0 if that was selected. it should be

 

$version = $_POST['passwordcrackers'];

 

// $version would be v2.0 or v3.0 etc, depending on which option was selected from the dropdown

 

if($version == 'v3.0')

{

  // user selected version 3.0

}

Link to comment
https://forums.phpfreaks.com/topic/222742-using-_post/#findComment-1151828
Share on other sites

oh blimey sorry desjardins2010, really wasn't thinking straight there. Think i was assuming you were looking to do something if the user selected "v3.0":

 

if(isset($_POST['submit']))
  {
    if($_POST['passwordcrackers'] == 'v3.0')
      {
         .... do or set set something
      }
    elseif(...something else)
      {
      }
   }

 

... my bad too much xmas food

Link to comment
https://forums.phpfreaks.com/topic/222742-using-_post/#findComment-1151845
Share on other sites

Don't use if(isset($_POST['submit'])) to test if a form has been submitted. Use:

 

if($_SERVER['REQUEST_METHOD'] == 'POST')

{

    // form is submitted

}

 

Using the isset way will mean that if the user presses the enter key to submit the form with internet explorer, your code will not pickup the fact that the form has been submitted.

Link to comment
https://forums.phpfreaks.com/topic/222742-using-_post/#findComment-1151893
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.