MxGucci Posted November 10, 2008 Share Posted November 10, 2008 Hi, I used to know how to code in PHP back in 2002, I need to refresh my memory while I create a new site. However, I am stuck with this code, it should be working as I got this off the net, and even got many other same type of codes, but for some reason they don't work on my site. I am trying to create a page so I can use Query String to direct my visitors to pages using index.php?section=x. Here is the code I have used: <? ini_set("register_globals", "on"); if($QUERY_STRING == "") { // Main Page echo "main page!!"; } elseif($QUERY_STRING == "about") { // About page echo "about page!!"; } elseif($QUERY_STRING == "contact") { // Contact page echo "contact page!!"; } else { // Page not found echo "Oops.. Page not found (404)"; } ?> -- When I went to www.tiltnation.com/beta/scripts/test.php .. it at first seems to work by saying "MAIN PAGE!!" but when I go to www.tiltnation.com/beta/scripts/test.php?=contact .. it still says "MAIN PAGE!!" So I went and found another snippet off a site, and still same thing, below is the code I used for this snippet: <?php $page = $GET['page']; switch ($page) { case '1': echo 'This is page 1'; break; case '2': echo 'This is Page 2'; break; case '3': echo 'This is Page 3'; break; default: echo "Sorry Page $page doesn't exist"; break; } ?> The link is www.tiltnation.com/beta/scripts/switch.php .. again actual page says what it should, but when I go www.tiltnation.com/beta/scripts/switch.php?page=1 .. nothing happens. Can someone PLEASE HELP!? Could this be something to do with my server settings? I am with godaddy hosting, how do I edit the php settings? Thanks for your help! Link to comment https://forums.phpfreaks.com/topic/132188-solved-using-query-string-indexphpsectionx-help/ Share on other sites More sharing options...
premiso Posted November 10, 2008 Share Posted November 10, 2008 Alot has changed since 2002. Don't use register_globals bad practice and exploitable. Instead of using QUERY_STRING, use $_GET and $_POST. The main problem is you forgot the _ in $GET, it needs that underscore to check correctly. Link to comment https://forums.phpfreaks.com/topic/132188-solved-using-query-string-indexphpsectionx-help/#findComment-687029 Share on other sites More sharing options...
MxGucci Posted November 10, 2008 Author Share Posted November 10, 2008 Alot has changed since 2002. Don't use register_globals bad practice and exploitable. Instead of using QUERY_STRING, use $_GET and $_POST. The main problem is you forgot the _ in $GET, it needs that underscore to check correctly. Thanks for your help, could you possibly tell me where I would use $_GET and $_POST in the first snippet I had pasted? Please and thank you! Link to comment https://forums.phpfreaks.com/topic/132188-solved-using-query-string-indexphpsectionx-help/#findComment-687032 Share on other sites More sharing options...
rhodesa Posted November 10, 2008 Share Posted November 10, 2008 <?php //The next line was missing the underscore in $_GET $page = $_GET['page']; switch ($page) { case '1': echo 'This is page 1'; break; case '2': echo 'This is Page 2'; break; case '3': echo 'This is Page 3'; break; default: echo "Sorry Page $page doesn't exist"; break; } ?> Link to comment https://forums.phpfreaks.com/topic/132188-solved-using-query-string-indexphpsectionx-help/#findComment-687033 Share on other sites More sharing options...
MxGucci Posted November 10, 2008 Author Share Posted November 10, 2008 <?php //The next line was missing the underscore in $_GET $page = $_GET['page']; ?> Thanks a lot guys! Wow this site is amazing, I've wasted an hour trying to figure it out, and you guys helped me out in 2 minutes. Much appreciated!! Link to comment https://forums.phpfreaks.com/topic/132188-solved-using-query-string-indexphpsectionx-help/#findComment-687037 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.