phpcodec Posted July 1, 2008 Share Posted July 1, 2008 I have some variables like this: $test1 = '1'; $test2 = '2'; $test3 = '3'; $test4 = '4'; and the url was http://www.somewebsites.com/index.php?word=test3 I tried: $var = $_GET['word']; echo $$var; so in theory it should echo 3 or if the url was word=test2 it would echo 2 but it does not do this, how can i solve this? Link to comment https://forums.phpfreaks.com/topic/112831-solved-variables/ Share on other sites More sharing options...
jonsjava Posted July 1, 2008 Share Posted July 1, 2008 try <?php $var = "test".$_GET['word']; echo $$var; ?> you still need to sanitize your input. Link to comment https://forums.phpfreaks.com/topic/112831-solved-variables/#findComment-579520 Share on other sites More sharing options...
phpcodec Posted July 1, 2008 Author Share Posted July 1, 2008 i'm sorry, but that does not work either Link to comment https://forums.phpfreaks.com/topic/112831-solved-variables/#findComment-579536 Share on other sites More sharing options...
DarkWater Posted July 1, 2008 Share Posted July 1, 2008 Does it echo nothing at all? Are the variables being set on that page (stupid question, but people have come here over stupider things)? Echo $_GET['word'] and make sure it's what you expect. Link to comment https://forums.phpfreaks.com/topic/112831-solved-variables/#findComment-579537 Share on other sites More sharing options...
phpcodec Posted July 1, 2008 Author Share Posted July 1, 2008 it echo's $test2 Link to comment https://forums.phpfreaks.com/topic/112831-solved-variables/#findComment-579546 Share on other sites More sharing options...
jonsjava Posted July 1, 2008 Share Posted July 1, 2008 oops. I wrote mine as follows <?php $test1 = '1'; $test2 = '2'; $test3 = '3'; $test4 = '4'; if (isset($_GET['word'])){ $var = "test".$_GET['word']; echo $$var; } and i called it as such: page.php?word=1 Link to comment https://forums.phpfreaks.com/topic/112831-solved-variables/#findComment-579548 Share on other sites More sharing options...
phpcodec Posted July 1, 2008 Author Share Posted July 1, 2008 thanks solved! Link to comment https://forums.phpfreaks.com/topic/112831-solved-variables/#findComment-579552 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.