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
User id in validate class - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: General (https://userspice.com/forums/forumdisplay.php?fid=20)
+--- Forum: New to UserSpice? (https://userspice.com/forums/forumdisplay.php?fid=22)
+--- Thread: User id in validate class (/showthread.php?tid=351)



User id in validate class - thenumbernine - 11-20-2016

I'm trying to validate a form against the user's id in the validate class, using something like the following:

$query = "SELECT * FROM users WHERE username = '{$value}' AND id = {$id}";

What's the proper syntax for grabbing the id within this class?


User id in validate class - mudmin - 11-20-2016

You're looking for
$query = “SELECT * FROM users WHERE username = ? AND id = ?”,array($value,$user->data()->id));


User id in validate class - thenumbernine - 11-20-2016

This throws the following error on the corresponding line:

Parse error: syntax error, unexpected ',' in /home/public/users/classes/Validate.php


User id in validate class - mudmin - 11-20-2016

Sorry about that...I was mainly focused on the end of your query and missed the beginning.
Code:
$query = $db->query("SELECT * FROM users WHERE username = ? AND id = ?",array($value,$user->data()->id));

Then if you want all the results it is
Code:
$results = $query->results();

If you only need the first row or only expect one row and don't want to loop through results,
Code:
$first = $query->first();

If you only need to know the number of rows returned...
Code:
$count = $query->count();



User id in validate class - thenumbernine - 11-20-2016

It's now returning the following error:

Fatal error: Call to a member function query() on null in /home/public/users/classes/Validate.php

Are the user details not being fetched?


User id in validate class - mudmin - 11-20-2016

I'm not really sure why this is happening in the Validate class. One thing to note that if you modify our class and then update, you could lose those changes. It's probably better to create a Validate2.php class.

That said, take a look at the User class since it does db queries.

You need a construct....
$this->_db = DB::getInstance();

Then when you construct your queries it is
$query = $this->_db->query(" your query....