r/PHPhelp • u/Ok_Effective_6601 • Jan 13 '25
Solved Hello PHPeers
I'm testing to see if I can post or if my post will be removed by Reddit. I'm a newbie both on Reddit and on here. I'm slowly developing an interest in PHP so Learner Alert!
Edit: I finally managed to post lol. So here goes my question:
So I'm building a PHP POS System using an Admin LTE template and local hosting on Xampp. I'm stuck on:
Notice\: Undefined index: user in* C:\xampp\htdocs\pos\controllers\users.controller.php on line 29*
This does not allow me to log in to the POS system as an admin. I've tried isset but nothing and I've been on this for hours. It's probably a " mark somewhere. Please help. Here is a Google Doc link containing all relevant code files and have highlighted line 29. I'm kinda new to backend so please bear with me. Please help.
Oh, and if there is a better way to post the code please let me know. Thanks in advance.
2
u/Ok_Effective_6601 Jan 13 '25
Apparently the exact column names on my database was the issue. Thank you all PHPeers!
1
u/Big-Dragonfly-3700 Jan 13 '25
The value returned by the MdlShowUsers() method call can be a boolean false value, if the query didn't match a row of data or depending on the error handling in place, a query error has occurred. You MUST test the returned value and only use it if it is a boolean true value.
There's a commented out line of code using var_dump($answer['user']), what does using var_dump($answer); show?
3
u/ceekayvilla Jan 13 '25
Welcome to the family
2
u/mrdarknezz1 Jan 13 '25
Pastebin is a good alternative to post code to, or just post the line with the error.
As the error says "Undefined index: user" it means that the variable does not have an index called "user". In php you can't access an undefined array index.
2
u/eurosat7 Jan 13 '25
Here is a little trick:
hth
1
u/CapNigiri Jan 13 '25
Just pass $user and $password to the function like an argument, it will be easier. I looked just shortly in but I think the problem is that you are using just fetch. Try to use fetch(PDO::FETCH_ASSOC) to return an associative array key(column name)=>value(column value). I'm a newbie too so I hope this can help!