Hi
I am having a little problem. The problem is I am getting an undefined array key Age warning in the code below.
I tried to use an earlier version of php (8.2 available) but I still get this warning.
Any help will be appreciated.
Thanks.
$age = " ";
if (!empty($age) ){
$age = $_GET["Age"];
}
Since you say it's an array error then I have to ask: Are you sure you have a URL query string parameter named 'Age'?
Your form has 'method="POST"'. Try the POST array instead of the GET array.
Hi @tudsy,
The issue you're facing is due to PHP 8.0+ throwing a warning when accessing an undefined array key. You can fix it by checking if the key exists before using it:
php
Copy
Edit
$age = $_GET["Age"] ?? "";
or
php
Copy
Edit
$age = isset($_GET["Age"]) ? $_GET["Age"] : "";
This way, if Age isn’t set, $age remains an empty string instead of causing a warning.
I recently worked on a project where I had to handle similar PHP warnings while building a website about Surah Yaseen (https://suraheyaseen.com/). Ensuring clean, error-free PHP code was crucial for smooth performance, especially when handling user input dynamically. If you're working on a PHP-based site, making these checks early helps avoid such issues.
Hope this helps! Let me know if you need further clarification.
Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)