PHP isset for an Array
-
Previously with help of this forum I was able to fix Undefined variable errors using if(isset()) for PHP 8.1. But this time I was unable to use if(isset()) to fix this error_log: PHP Warning: Undefined variable $sendid in /home/____/check.php on line 70 Code line 70 is
printm($str.$sendid);
As above line connected with an array, how can I use isset? Please suggest me a solution. Full code is given below:
DATE_SUB(NOW(), INTERVAL ".C_REG_DAYS." DAY)");
$row=mysqli_fetch_array($temp);
$count = $row['total'];
if($count != '0') {
mysqli_query($conn,"DELETE FROM ".C_MYSQL_TEMP." WHERE id='".$id."' AND code='".$code."'");
if(C_CHECK_REGISTER == '3') {
$status='1';
$str=$w[159];
}
else {
$status='7';
$str = $w[46];
}
mysqli_query($conn,"UPDATE ".C_MYSQL_MEMBERS." SET status='".$status."' WHERE id='".$id."'");
$result = mysqli_query($conn,'SELECT email, password FROM '.C_MYSQL_MEMBERS.' WHERE id = \''.$id.'\'');
while($i=mysqli_f -
Previously with help of this forum I was able to fix Undefined variable errors using if(isset()) for PHP 8.1. But this time I was unable to use if(isset()) to fix this error_log: PHP Warning: Undefined variable $sendid in /home/____/check.php on line 70 Code line 70 is
printm($str.$sendid);
As above line connected with an array, how can I use isset? Please suggest me a solution. Full code is given below:
DATE_SUB(NOW(), INTERVAL ".C_REG_DAYS." DAY)");
$row=mysqli_fetch_array($temp);
$count = $row['total'];
if($count != '0') {
mysqli_query($conn,"DELETE FROM ".C_MYSQL_TEMP." WHERE id='".$id."' AND code='".$code."'");
if(C_CHECK_REGISTER == '3') {
$status='1';
$str=$w[159];
}
else {
$status='7';
$str = $w[46];
}
mysqli_query($conn,"UPDATE ".C_MYSQL_MEMBERS." SET status='".$status."' WHERE id='".$id."'");
$result = mysqli_query($conn,'SELECT email, password FROM '.C_MYSQL_MEMBERS.' WHERE id = \''.$id.'\'');
while($i=mysqli_fThe variable
$sendid
is not defined anywhere at module level, it is local to the followingswitch
block:switch (C_ID) {
case '2':
$sendid=$i['email'];
break;
default:
$sendid=$id;
break;
}So once that block ends the variable no longer exists. Change it to something like:
$sendid = '';
switch (C_ID) {
global $sendid; // tell switch to use the global variable
case '2':
$sendid=$i['email'];
break;
default:
$sendid=$id;
break;
}You may like to review PHP: Variable scope - Manual[^].
-
The variable
$sendid
is not defined anywhere at module level, it is local to the followingswitch
block:switch (C_ID) {
case '2':
$sendid=$i['email'];
break;
default:
$sendid=$id;
break;
}So once that block ends the variable no longer exists. Change it to something like:
$sendid = '';
switch (C_ID) {
global $sendid; // tell switch to use the global variable
case '2':
$sendid=$i['email'];
break;
default:
$sendid=$id;
break;
}You may like to review PHP: Variable scope - Manual[^].
I tried using your code suggestion but when user recieved verification email and clicked on verify link, it gives "HTTP ERROR 500". Also error_log has following: PHP Parse error: syntax error, unexpected 'global' (T_GLOBAL), expecting case (T_CASE) or default (T_DEFAULT) or '}'
-
I tried using your code suggestion but when user recieved verification email and clicked on verify link, it gives "HTTP ERROR 500". Also error_log has following: PHP Parse error: syntax error, unexpected 'global' (T_GLOBAL), expecting case (T_CASE) or default (T_DEFAULT) or '}'
-
HTTP status 500 is an internal server error. So you need to look at your server logs, and maybe even add some debug code to find out what is going wrong. Is this your code or did someone else write it?
-
Actually issue has been fixed after adding your code suggestion to another place in the same PHP file:
$tm=array($sendid,'____',C_SNAME);
$message=template($w[588],$tm);
sendmail(C_FROMM,$i['email'],$subject,$message,'text');
}
$sendid = '';
global $sendid;
printm($str.$sendid);
} -
Udaya Arunakantha wrote:
this code was written by an outside person.
Then you have my sympathy. I have faced similar issues in the past and it is never easy.