View Full Version : substr(lastname, 0, 3) and 6 random chars after?

09-18-2008, 02:24 PM
How to execute this idea below?

You register with your details and you add your lastname.
I want to add your password with the first three chars of your last name.
So lets say your lastname is johnson your password would be johkvygce

$random_chars = substr($_POST["lastname"], 0, 3);
$random_chars .= substr(str_shuffle('abcdefghjkmnpqrstuvwxyz'), 0, 6);
$random_pass = $_POST["lastname"].$random_chars;

<input type="text" name="memnum" id="memnum" value="<?php echo $random_pass;?>" />

Is this straight forward as insert into, bla, bla, $random_pass or is it a bit more complicated? It aint working like that so it's more complicated :mrgreen: (for me that is :roll: )


09-18-2008, 02:44 PM

$lastname = "johnson";
$random_chars = substr(str_shuffle('abcdefghjkmnpqrstuvwxyz'), 0, 6);

$lastname = substr($lastname, 0, 3);

echo $lastname.$random_chars;

hint: you need to look at your variable names

09-18-2008, 02:46 PM
Yes that's fine, but is it a two page process before the insert or one?

09-18-2008, 02:57 PM
up to you.

just use the $random_pass variable in your sql statment

09-18-2008, 05:52 PM
That above code that I posted was stupid, please delete it.
I was and am very tired - really not thinking what so ever!.


09-18-2008, 05:56 PM
have you fixed your problem now?

09-19-2008, 12:55 AM
its not stupid, if it is was then we are all morons (some of the time) :)

09-19-2008, 06:57 AM
have you fixed your problem now?
Yes it was a bit(sorry hugely) lazy of me and should have thought it through properly.

The proper method(for me :mrgreen: );
You register your details - Lastname, etc...
The form enters the random chars in a field I can use later.

So in the DB I have;

lastname = post[lastname]
random= post[random_chars]

Now I can use it on any page and with anything.

$r_lname = substr($row["lastname"], 0, 3);
$r_lname .= $row["random"];
echo $r_lname;

This is untested code.

09-19-2008, 06:59 AM
its not stupid, if it is was then we are all morons (some of the time) :)
Thanks dude ;-) , I think I was too freakin' lazy to even think.