Jump to content

Functions wont run - problem :o


quelle

Recommended Posts

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
}
?>

Link to comment
https://forums.phpfreaks.com/topic/222021-functions-wont-run-problem-o/
Share on other sites

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.

 

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 :)

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"]) {

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.