php - Get an output from a <select> field with $_POST when a submit button is clicked -


i'm making rock paper scissors game , players need choose if want play best out of 1, 3, 5 or 7 before start game , need work select field , submit button.

i new select tag suit me best if selected number exctracted $_post or $_get

this form:

<form method="post"> <h1>best out of </h1> <select>     <option value="one">1</option>     <option value="three">3</option>     <option value="five">5</option>     <option value="seven">7</option> </select> <input type="submit" name="start" value="start" /> </form> 

this php:

<?php     if(isset($_post['start']) && isset($_post['one']))     {         echo "do 1";     };     if(isset($_post['start']) && isset($_post['three']))     {         echo "do 2";     };     if(isset($_post['start']) && isset($_post['five']))     {         echo "do 3";     };     if(isset($_post['start']) && isset($_post['seven']))     {         echo "do 4";     }; ?> 

give select name attribute

<form method="post"> <h1>best out of </h1> <select name="my_select">     <option value="one">1</option>     <option value="three">3</option>     <option value="five">5</option>     <option value="seven">7</option> </select> <input type="submit" name="start" value="start" /> </form> 

after submitting form in php script can select value using $_post array index my_select ( name attribute value of select element):

<?php if(isset($_post['start']) && isset($_post['my_select'])) {     if($_post['my_select'] === 'one'){}     .... } ?> 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -