r/PHPhelp • • Nov 01 '25

Solved Undefined Array Key - Send Help!

Hello,

Looking for some assistance. I am currently doing a course on PHP and inputting data from a database but I'm getting an error "Undefined array key"

Can someone help me and tell me what I've missed?

https://pastebin.com/kepyjqyq

The code was copy and pasted direct from what the lecturer gave us.

I'd ask my lecturer but with it being the weekend they are unavailable until Monday and this is annoying me.

Thanks

3 Upvotes

11 comments sorted by

View all comments

Show parent comment

3

u/allen_jb Nov 01 '25

What version of PHP are you using? I'd expect to see an error for queries that reference a non-existent table.

For PHP versions older than 8.0 you may want to explicitly set the PDO error mode to exceptions, as in Example #1 here. (Exceptions are the default error mode since PHP 8.0 - in previous versions, using the "silent" mode, you had to explicitly check every query for errors)

Also add the following lines to the beginning on your code (after the first <?php):

error_reporting(E_ALL);
ini_set('display_errors', 1);