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
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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.