MasterACE14 Posted December 24, 2007 Share Posted December 24, 2007 Hello Everyone, in my index.php page I have a basic switch statement which is used with $_GET['page'] so I can display different pages within index.php. Which makes the URL look like this(no matter what page I am on): /index.php?page=mash Now, my problem is, I am trying to send a GET in a form in mash.php(the URL above). But what is happening is, the submitted GET is replacing the page GET, so my URL looks like this once the submit button is clicked: /index.php?health_needed=35 And when this happens there is 2 problems: 1. The home page is loaded instead of mash.php which is in the form. 2. nothing can be done with the submitted data as it isn't submitted to mash.php So how do I submit the GET to mash.php without screwing up the URL? I believe its gotta be something along the lines of /index.php?page=mash&health_needed=35 But i'm not completely sure. here is my form incase it helps: <?php //$health_needed = 35; in my example ?> <form name="mash_treatment" method="get" action="index.php?page=mash&"> <input type="hidden" name="health_needed" value="<?=$health_needed?>"> <input type="submit" value="Receive Treatment"> </form> Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/82986-solved-2-gets-in-the-same-url-not-working/ Share on other sites More sharing options...
Cep Posted December 24, 2007 Share Posted December 24, 2007 You should be using $_GET['health_needed']; in your php script to retrieve the value. Quote Link to comment https://forums.phpfreaks.com/topic/82986-solved-2-gets-in-the-same-url-not-working/#findComment-422061 Share on other sites More sharing options...
MasterACE14 Posted December 24, 2007 Author Share Posted December 24, 2007 I am... here's the rest of the code: <?php $health_needed = $player_maxhealth - $player_currenthealth; if(!isset($_GET["health_needed"])) { if($player_currenthealth < $player_maxhealth) { echo "You have been wounded in battle, if you would like to receive medical treatment you can receive it now for <b>$500</b>."; ?> <br><br> <form name="mash_treatment" method="get" action="index.php?page=mash&"> <input type="hidden" name="health_needed" value="<?=$health_needed?>"> <input type="submit" value="Receive Treatment"> </form> <?php } } elseif(isset($_GET["health_needed"]) && $player_currenthealth < $player_maxhealth) { $health_you_need = $_GET["health_needed"]; mysql_query("UPDATE `cf_users` SET `currenthealth` = currenthealth+$health_you_need WHERE `id`='" . $player_accountid . "' LIMIT 1") or die('Query:<br /> Updating your Current Health in M*A*S*H <br /><br />Error:<br />' . mysql_error()); mysql_query("UPDATE `cf_users` SET `money` = money-500 WHERE `id`='" . $player_accountid . "' LIMIT 1") or die('Query:<br /> Updating your money in M*A*S*H <br /><br />Error:<br />' . mysql_error()); echo "You are now back to full health!"; unset($_GET["health_needed"]); } if($player_currenthealth == $player_maxhealth) { echo "You do not require medical treatment."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/82986-solved-2-gets-in-the-same-url-not-working/#findComment-422069 Share on other sites More sharing options...
MasterACE14 Posted December 24, 2007 Author Share Posted December 24, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/82986-solved-2-gets-in-the-same-url-not-working/#findComment-422085 Share on other sites More sharing options...
Northern Flame Posted December 24, 2007 Share Posted December 24, 2007 why not try using $_POST instead of $_GET? Quote Link to comment https://forums.phpfreaks.com/topic/82986-solved-2-gets-in-the-same-url-not-working/#findComment-422094 Share on other sites More sharing options...
MasterACE14 Posted December 24, 2007 Author Share Posted December 24, 2007 am I able to POST back to the same page? Quote Link to comment https://forums.phpfreaks.com/topic/82986-solved-2-gets-in-the-same-url-not-working/#findComment-422203 Share on other sites More sharing options...
jitesh Posted December 24, 2007 Share Posted December 24, 2007 This is the perfect way. - /index.php?page=mash&health_needed=35. If you want the url like this /index.php?health_needed=35 then you need to pass value of page in hidden variable. <form> <input type="hidden" name="page" value="mash"> </form> And need to use REQUEST['page'] inseted of $_GET['page']. Quote Link to comment https://forums.phpfreaks.com/topic/82986-solved-2-gets-in-the-same-url-not-working/#findComment-422210 Share on other sites More sharing options...
cooldude832 Posted December 24, 2007 Share Posted December 24, 2007 This is the perfect way. - /index.php?page=mash&health_needed=35. If you want the url like this /index.php?health_needed=35 then you need to pass value of page in hidden variable. <form> <input type="hidden" name="page" value="mash"> </form> And need to use REQUEST['page'] inseted of $_GET['page']. Very far from perfect First your form has no action and no way to submit it so I don't see a use to it. Secondly you dont' define a process type (GET/POST) for it Thirdly $_REQUEST is a bloated superglobal that could be injected so for a not perfect solution use what they posted Quote Link to comment https://forums.phpfreaks.com/topic/82986-solved-2-gets-in-the-same-url-not-working/#findComment-422212 Share on other sites More sharing options...
kenrbnsn Posted December 24, 2007 Share Posted December 24, 2007 The default action in a form is to send the information back to the page the form is on. The default method is "GET". Ken Quote Link to comment https://forums.phpfreaks.com/topic/82986-solved-2-gets-in-the-same-url-not-working/#findComment-422213 Share on other sites More sharing options...
cooldude832 Posted December 24, 2007 Share Posted December 24, 2007 The default action in a form is to send the information back to the page the form is on. The default method is "GET". Ken Defaults, but is that acid2 way of doing it? When all browsers go acid2 in fifty years will that still work? Quote Link to comment https://forums.phpfreaks.com/topic/82986-solved-2-gets-in-the-same-url-not-working/#findComment-422217 Share on other sites More sharing options...
MasterACE14 Posted December 24, 2007 Author Share Posted December 24, 2007 acid2? Quote Link to comment https://forums.phpfreaks.com/topic/82986-solved-2-gets-in-the-same-url-not-working/#findComment-422320 Share on other sites More sharing options...
predator Posted December 24, 2007 Share Posted December 24, 2007 do ya still need help with this mate? Quote Link to comment https://forums.phpfreaks.com/topic/82986-solved-2-gets-in-the-same-url-not-working/#findComment-422341 Share on other sites More sharing options...
wildteen88 Posted December 24, 2007 Share Posted December 24, 2007 The default action in a form is to send the information back to the page the form is on. The default method is "GET". Ken Defaults, but is that acid2 way of doing it? When all browsers go acid2 in fifty years will that still work? The acid2 test has nothing to do with how forms are submitted. The acid2 test is just a benchmark for how well browsers support standards. Quote Link to comment https://forums.phpfreaks.com/topic/82986-solved-2-gets-in-the-same-url-not-working/#findComment-422387 Share on other sites More sharing options...
cooldude832 Posted December 24, 2007 Share Posted December 24, 2007 Acid2 is a standard put forth that all browsers are suppose to achieve at some point for rendering xhtml/html. The default way to handle a form would be part of the Acid2 criteria as it falls under the scope of xhtml/html rendering. Also I believe w3 compliance to transitional or strict doc types fail when a form lacks a method or action. Quote Link to comment https://forums.phpfreaks.com/topic/82986-solved-2-gets-in-the-same-url-not-working/#findComment-422470 Share on other sites More sharing options...
MasterACE14 Posted December 24, 2007 Author Share Posted December 24, 2007 do ya still need help with this mate? I'm good thanks, I'm gonna change the method to a POST. Thanks again guys. Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/82986-solved-2-gets-in-the-same-url-not-working/#findComment-422640 Share on other sites More sharing options...
corbin Posted December 24, 2007 Share Posted December 24, 2007 Bleh.... When ever you submit a form using GET, IE and FF (and probably others) use the base url put into the action tag, not any additional information with it. Also if <input type="text" name="name" value="corbin" /> would make ?name=corbin (if not changed), then why wouldn't <input type="hidden" name="page" value="somepage" /> make ?page=somepage ? I use get forms for a lot of things, and I have to do that all the time. So my next question.... If it all goes into the url, why would you need to use $_REQUEST instead of the better $_GET? Anyway, hope I helped, and yes, sorry for basically repeating everything others said. Quote Link to comment https://forums.phpfreaks.com/topic/82986-solved-2-gets-in-the-same-url-not-working/#findComment-422647 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.