The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once



UserSpice
profile.php "User doesn't exist" - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28)
+--- Forum: Modifications and Hackery (https://userspice.com/forums/forumdisplay.php?fid=29)
+--- Thread: profile.php "User doesn't exist" (/showthread.php?tid=518)



profile.php "User doesn't exist" - Caspar Leo - 04-09-2017

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.


profile.php "User doesn't exist" - Caspar Leo - 04-14-2017

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.