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
/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
Find id by username
#1
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.
  Reply
#2
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.
  Reply
#3
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.
  Reply
#4
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.
  Reply
#5
Ok....so you basically want

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

$random = $rnd1."-".$rnd2;
  Reply
#6
Thanks, sorry for messing up your language that is VB oozing out.
  Reply
#7
haha no problem. It takes a little getting used to.
  Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)