shyami Posted March 22, 2007 Share Posted March 22, 2007 Hi, i am generating text boxes randomly in one page, after press submit button, i am getting value in 2nd page. for that in 2nd page i wrote like this for($i=0;$i<50;$i++) { $val="$text".$i; echo $val //=> $text1 (name of the text box) echo $text1 //=> it is giving correct value } when i am giving directly echo $text1, then i am getting correct value. but this $val is having my text box name, if i am giving echo $val, it is just printing the name of the text box. i need to print the value of the textbox. how to do this? plz help me in this. Thanks Shyami Link to comment https://forums.phpfreaks.com/topic/43794-how-to-get-a-value-from-variable/ Share on other sites More sharing options...
Lumio Posted March 22, 2007 Share Posted March 22, 2007 Try echo $$val; The second $ says that php has to use the variable named like the value of $val It's also better to use $_POST. (http://at2.php.net/manual/en/reserved.variables.php) So if you try to put that varis out: echo $_POST[$val]; Link to comment https://forums.phpfreaks.com/topic/43794-how-to-get-a-value-from-variable/#findComment-212618 Share on other sites More sharing options...
Iceman512 Posted March 22, 2007 Share Posted March 22, 2007 Hi Shyami, Following on from Lumio's post, it might help you to declare the value of $val in a variable of it's own first. Try this: <?php $getvalue = $_POST[$val]; // Now you should be able to retrieve the text box contents by: echo $getvalue; for($i=0;$i<50;$i++) { $val="$text".$i; echo $val //=> $text1 (name of the text box) echo $text1 //=> it is giving correct value } ?> Post again if you still have problems. Regards, Iceman Link to comment https://forums.phpfreaks.com/topic/43794-how-to-get-a-value-from-variable/#findComment-212646 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.