EmperorZenos Posted June 23, 2009 Share Posted June 23, 2009 How can I use PHP with the <option> tag?I mean making PHP see what is selected from this list, and use it in an if statement. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 23, 2009 Share Posted June 23, 2009 When they submit the form the value that they selected will be submitted under the name of the select element. If you have a select element called "test", and a chosen option with a value of "abc", and the form is submitted using the post method, in PHP the variable $_POST['test'] will have the value "abc". Link to comment Share on other sites More sharing options...
smerny Posted June 23, 2009 Share Posted June 23, 2009 <form action='mypage.php' method='post> <select name='something'> <option value='this' />this <option value='that' />that </select> <input type='submit' value='submit'></form> mypage.php can then access that information with... <?php if ($_POST['something'] = 'this') { echo 'this was selected' } else { echo 'that was selected' }?> Link to comment Share on other sites More sharing options...
EmperorZenos Posted June 23, 2009 Author Share Posted June 23, 2009 Thank you very much to the both of you, the code worked. Link to comment Share on other sites More sharing options...
Ingolme Posted June 23, 2009 Share Posted June 23, 2009 <form action='mypage.php' method='post> <select name='something'> <option value='this' />this <option value='that' />that </select> <input type='submit' value='submit'></form> mypage.php can then access that information with... <?php if ($_POST['something'] = 'this') { echo 'this was selected' } else { echo 'that was selected' }?> What your operators there! if ($_POST['something'] = 'this')is differrent than if ($_POST['something'] == 'this') Link to comment Share on other sites More sharing options...
Synook Posted June 23, 2009 Share Posted June 23, 2009 Yes: <option value='this'>this</option> Yes: <option value='this'>this No!: <option value='this' />this Think about it... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.