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
/printthread.php 16 require_once



UserSpice
Find id by username - 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: Find id by username (/showthread.php?tid=317)



Find id by username - CromeX - 10-21-2016

Hi,
I am new to userspice and my experience with PHP is two months, so forgive me if I am a bit slow. I have added a new column to the users table. I want to add a random number to this column for each user after register, trying to do that in join.php.
Here is what I have done so far

this is to get the id
<pre>
Code:
$user_name=Input::get('username');
$user_n = $db->get('users',['username','=',$user_name]);
</pre>


then insert it
Code:
$db->update('deposit_id',$the_id,$fields);

nothing is happening, what am I doing wrong?
Any help would be appreciated trying to recommend this app for a project.
Thanks in advance.



Find id by username - mudmin - 10-21-2016

I will say that vericode in the users table is a randomly generated 6 digit number, if that would happen to work for your purposes. In the event that say you only need a 4 digit random number you could echo that back cutting off the last 2 digits.

So that would look like

Code:
$random = substr($user->data()->vericode, 0, -2);

But...back to your question.

If you're going to modify core userspice files, like the join form, it is best to copy join.php over to usersc/
This allows you to mod these files without having our updates overwrite your changes.

So, I'd copy your file over to usersc and change line 24 to say
Code:
<?php require_once '../users/init.php'; ?>

This allows UserSpice to find its main configuration file.

Then, around line 38, I would generate your random number. Let's say you need your own, custom 4 digit number...
Code:
$random = rand(0000,9999);

Finally, since you are putting this info into the users table (which is where the join form is already updating), you just need to pass your random number into the existing array of info being updated. So let's say you called your column in the db random_number....

Right after line 170 and again on line 196 add this line...
Code:
'random_number' => $random,

That tells Userspice to take the random number you generated on line 38 and pass it into the database into the column, random_number

I hope that helps. Let me know if you have any issues.



Find id by username - mudmin - 10-21-2016

I should add, when it comes time to echo out this information, you don't have to do a database query because there is an auto-generated one for the entire user line in the db. So if you need to you can call back something like

echo $user->data()->vericode;
or
$vericode = $user->data()->vericode;
or if you are in the middle of html you can do a quick echo in php of
<?=$user->data()->vericode?>

The same thing would work for your random_number column.


Find id by username - CromeX - 10-21-2016

Thanks much,
The random number I am trying to generate should look XXXX-XXXX This is my attempt so far

<pre>
Code:
$deposit_id1=rand(1000,9999);
$deposit_id2=rand(1000,9999);
$deposit_id=$deposit_id1 &"-"& $deposit_id2;
</pre>

and it must be unique to every record

I'll try to find a way to use your way less head ace for me

Again thanks a lot.


Find id by username - mudmin - 10-21-2016

Ok....so you basically want

$rnd1 = rand(0000,9999);
$rnd2 = rand(0000,9999);

$random = $rnd1."-".$rnd2;



Find id by username - CromeX - 10-21-2016

Thanks, sorry for messing up your language that is VB oozing out.


Find id by username - mudmin - 10-21-2016

haha no problem. It takes a little getting used to.