The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> undefined array key
tudsy
post Oct 5 2024, 11:38 PM
Post #1


Serious Coder
*****

Group: Members
Posts: 252
Joined: 30-September 14
Member No.: 21,611



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"];

}
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Oct 6 2024, 03:44 AM
Post #2


Programming Fanatic
********

Group: Members
Posts: 2,013
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



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'?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
tudsy
post Oct 6 2024, 04:13 AM
Post #3


Serious Coder
*****

Group: Members
Posts: 252
Joined: 30-September 14
Member No.: 21,611



QUOTE(CharlesEF @ Oct 6 2024, 06:14 PM) *

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'?



Yes.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
tudsy
post Oct 6 2024, 07:26 AM
Post #4


Serious Coder
*****

Group: Members
Posts: 252
Joined: 30-September 14
Member No.: 21,611



QUOTE(tudsy @ Oct 6 2024, 06:43 PM) *

QUOTE(CharlesEF @ Oct 6 2024, 06:14 PM) *

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'?



Yes.



Hi

the relevant files are:

form.php -> process_doubleoptin.php

Thanks.


Attached File(s)
Attached File  process_doubleoptin.txt ( 5.56k ) Number of downloads: 138
Attached File  form.txt ( 6.01k ) Number of downloads: 486
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Oct 6 2024, 05:59 PM
Post #5


Programming Fanatic
********

Group: Members
Posts: 2,013
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Your form has 'method="POST"'. Try the POST array instead of the GET array.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
abuislam
post Feb 26 2025, 01:13 AM
Post #6





Group: Members
Posts: 7
Joined: 21-February 25
Member No.: 29,396



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.

This post has been edited by abuislam: Feb 26 2025, 01:14 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
11 User(s) are reading this topic (11 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th March 2025 - 01:59 AM