imdead Posted September 25, 2011 Share Posted September 25, 2011 I can't honestly see whats wrong with this code, it's print'ing correct with the print_r. Array ( [value1] => 2 [option] => - [value2] => 1 ) however i can't actually echo out the value1,value2 or option? It says the vars are empty yet it can still print_r the values so i know there not empty <?php if(isset($_POST["submit"])){ $value1=$_POST["value1"]; $value2=$_POST["value2"]; $option=$_POST["option"]; } print_r($_POST); echo"$value1"; ?> <form action="index.php" name="submit" method="post"> <input type="text" name="value1"> <select name="option"> <option>+</option> <option>-</option> <option>*</option> <option>/</option> </select> <input type="text" name="value2"> <input type="submit" value="submit"> </form> Link to comment https://forums.phpfreaks.com/topic/247854-no-idea-whats-wrong/ Share on other sites More sharing options...
LiquidFusi0n Posted September 25, 2011 Share Posted September 25, 2011 Hmm I don't know why the variable is showing as undefined but you can use the following code and it works. Also remember your <html> & <body> tags <?php if(isset($_POST["submit"])){ $value1=$_POST["value1"]; $value2=$_POST["value2"]; $option=$_POST["option"]; } echo $_POST['value1']; ?> <html> <body> <form action="test.php" name="submit" method="post"> <input type="text" name="value1"> <select name="option"> <option>+</option> <option>-</option> <option>*</option> <option>/</option> </select> <input type="text" name="value2"> <input type="submit" value="submit"> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/247854-no-idea-whats-wrong/#findComment-1272690 Share on other sites More sharing options...
LiquidFusi0n Posted September 25, 2011 Share Posted September 25, 2011 Sorry for the double post but I figured it out. Non of the values were being stored. You never gave submit a name <input type="submit" value="submit" name="submit"> Your code will now work --LiquidFusi0n Link to comment https://forums.phpfreaks.com/topic/247854-no-idea-whats-wrong/#findComment-1272693 Share on other sites More sharing options...
Pikachu2000 Posted September 25, 2011 Share Posted September 25, 2011 To be valid markup, the <option> tags need a name= attribute also. Not necessarily saying that's the cause of this problem, but some browsers may choose not to send a value for the <select> field if the <option> tags are missing the name= attributes. Link to comment https://forums.phpfreaks.com/topic/247854-no-idea-whats-wrong/#findComment-1272694 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.