quelle Posted December 17, 2010 Share Posted December 17, 2010 Ive got some like code like this (this is a part of my source, it'll be enough to solve my problem). I've got 4 functions here trying to run them using switch statement, but only the default one is running, why ? <?php //******PETLJA ZA MENI*******// switch(@$HTTP_GET_VARS["method"]) { case "ShowAdd": GetNewPollDetails(); break; case "AddFinal": AddPoll(); break; case "ShowDelete": GetPollToDelete(); break; case "DeleteFinal": DeletePoll(); break; default: GetChoice(); } function GetChoice(){ ?> <ul> <li><h2><a href="managepoll.php?method=ShowAdd">Dodaj anketu</a></h2></li> <li><h2><a href="managepoll.php?method=ShowDelete">Izbrisi anketu</a></h2></li> <li><h2><a href="managepoll.php?method=DeleteFinal">Pregledaj ankete</a></h2></li> </ul> <?php } ?> <?php function GetNewPollDetails(){ ?> <h1>Nova anketa</h1> <form name="DodajAnketu" action="managepoll.php?method=AddFinal"> <br /> Pitanje Ankete:<input name="text" type="text" width="150"/> <br /> Odogovor 1:<input name="text2" type="text" width="150"/> <br /> Odogovor 2:<input type="text" width="150"/> <br /> Odogovor 3:<input type="text" width="150"/> <br /> Odogovor 4:<input type="text" width="150"/> <br /> Odogovor 5:<input type="text" width="150"/> <br /> <input type="submit" value="Napravi" name="napravi" /> </form> <?php } ?> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 17, 2010 Share Posted December 17, 2010 echo $HTTP_GET_VARS["method"] to see what it is before the switch ps, that really should be something more like if (!empty($_GET["method"])) { switch($_GET["method"]) { add check for empty and user $_GET instead of http_get_vars. you might not be getting anything for http_get_vars because it is no longer used or configured in your PHP installation. Quote Link to comment Share on other sites More sharing options...
desjardins2010 Posted December 17, 2010 Share Posted December 17, 2010 read my mind prior to reading your post bluesky I was thinking the same in regards to format Quote Link to comment Share on other sites More sharing options...
quelle Posted December 18, 2010 Author Share Posted December 18, 2010 thanks it works now ;p btw i defined "method" as part of HTTP_GET_VARS array but I also hadn't to do that because php by itself creates variable for any values that I pass in from either a form or querystring, so an $method variable would be made for me right ? btw thanks again Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 18, 2010 Share Posted December 18, 2010 php by itself creates variable for any values that I pass in from either a form or querystring, so an $method variable would be made for me right ? NO, or at least it shouldn't. What you are referring to is register_globals, where all values submitted via GET or POST are automatically loaded into variables by the receiving script. This was a bad idea, should be disabled in your PHP (if it's turned on), and won't be available at all in newer PHP versions. You must always explicitly request the variable you want to use. $HTTP_GET_VARS was the old way. now it's $_GET, so use $_GET, and make sure the index is !empty before checking or comparing it's value: if (!empty($_GET["method"])) { switch($_GET["method"]) { Quote Link to comment Share on other sites More sharing options...
quelle Posted December 18, 2010 Author Share Posted December 18, 2010 okay thanks Quote Link to comment 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.