The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
profile.php "User doesn't exist"
#1
Hey,

I'm new to PHP and programming in general.
There is something I noticed while working with the UserSpice profile feature.

users/profile.php is working properly, if $userQ gets an existing user id. (line 34)
if a user id, in my case profile.php?id=4, does not exist in the table, php throws the following:


Notice: Undefined offset: 0 in C:\xampp\htdocs\userspice\users\classes\DB.php on line 155

Notice: Trying to get property of non-object in C:\xampp\htdocs\userspice\users\profile.php on line 46

Notice: Trying to get property of non-object in C:\xampp\htdocs\userspice\users\profile.php on line 47

Notice: Trying to get property of non-object in C:\xampp\htdocs\userspice\users\profile.php on line 49


So, we're declaring variables in if(isset($_GET['id'])){ , but obviously missing a check, if user id is an existing db entry. The else (line 53) will excecute, when there is nothing "to get". If there is, we have no fallback.

My thought was to make another query for checking if the $userID is in the table (findById?). But that doesn't work as expected..

So, after $thatUser = $userQ->first(); on line 35, i tried

if(empty($thatUser)){
die('No entry');
} else{

But still have the problem, that $userQ->first(); does not exist and causes the offset:0 error.
I think there is a fast and smoother way to accomplish this but i don't get it. Like:

if id isset
// check the id
if id exists
//if yes, return
// if not, do something else (some static html 'User does not exist')

Would be awesome if someone can help.
  Reply
#2
What i've added below $userQ

<pre>
Code:
$resultsQ = $userQ->results();

if (empty($resultsQ)) {
  // redirect
} else {

...
</pre>


Im not sure if it's the best solution, but it works.
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)