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;
}
}
?>
$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);
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.