0

I m using the following code in a PHP script I am trying to call a set of code through function calling(). When I call that function and run that script if shows me the error that the variable $querydigit is undefined.

Can any body tell me how I can call that set of code where I want it.

<?php //$querynum = $_SERVER['QUERY_STRING']; function calling() { if(isset($_GET[$querydigit]) && ($_GET[$querydigit]==1)) {$photoname = '1'; } else if(isset($_GET[$querydigit]) && ($_GET[$querydigit]==2)) {$photoname = '2'; } else if(isset($_GET[$querydigit]) && ($_GET[$querydigit]==3)) {$photoname = '3'; } else if(isset($_GET[$querydigit]) && ($_GET[$querydigit]==4)) {$photoname = '4'; } else if(isset($_GET[$querydigit]) && ($_GET[$querydigit]==5)) {$photoname = '5'; } else if(isset($_GET[$querydigit]) && ($_GET[$querydigit]==6)) {$photoname = '6'; } else if(isset($_GET[$querydigit]) && ($_GET[$querydigit]==7)) {$photoname = '7'; } else if(isset($_GET[$querydigit]) && ($_GET[$querydigit]==8)) {$photoname = '8'; } } if(isset($_GET['1'])) { $querydigit = 1; $photoseries = 8; $foldername = 'founder'; calling(); } else if(isset($_GET['2'])) { $querydigit = '2'; $photoseries = 8; $foldername = 'founder'; calling; } } ?> 
2
  • 3
    Define calling to accept an argument and pass the variable to it. Also, read about variable scope. Commented Feb 11, 2012 at 13:56
  • Also you can declare the variable as a global inside the function: 'global $querydigit;`. Commented Feb 11, 2012 at 14:00

1 Answer 1

4

$querydigit is not defined within function's scope. You can fix it in following way:

 function calling($querydigit) { 

and then call your function like this:

calling($querydigit); 

Here is your code fixed:

 <?php //$querynum = $_SERVER['QUERY_STRING']; function calling($querydigit) { if(isset($_GET[$querydigit]) && ($_GET[$querydigit]==1)) {$photoname = '1'; } else if(isset($_GET[$querydigit]) && ($_GET[$querydigit]==2)) {$photoname = '2'; } else if(isset($_GET[$querydigit]) && ($_GET[$querydigit]==3)) {$photoname = '3'; } else if(isset($_GET[$querydigit]) && ($_GET[$querydigit]==4)) {$photoname = '4'; } else if(isset($_GET[$querydigit]) && ($_GET[$querydigit]==5)) {$photoname = '5'; } else if(isset($_GET[$querydigit]) && ($_GET[$querydigit]==6)) {$photoname = '6'; } else if(isset($_GET[$querydigit]) && ($_GET[$querydigit]==7)) {$photoname = '7'; } else if(isset($_GET[$querydigit]) && ($_GET[$querydigit]==8)) {$photoname = '8'; } } if(isset($_GET['1'])) { $querydigit = 1; $photoseries = 8; $foldername = 'founder'; calling($querydigit); } else if(isset($_GET['2'])) { $querydigit = '2'; $photoseries = 8; $foldername = 'founder'; calling($querydigit); } ?> 
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your reply. i have fixed it with calling that function code through a include file also and that works too for me.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.