PHP Explode to MySQL

Soldato
Joined
28 Sep 2008
Posts
14,158
Location
Britain
Google is not quite returning anything useful, perhaps I'm searching for the wrong thing.

Basically, I have a form. Username, Email and Password.
I have a MySQDB with id, username, firstname, lastname, password

When the user registers using a strict (corporate) email, I would like the PHP to handle exploding the email (delimiting at the .) to automagically populate the database firstname and lastname.

ie, User form shows:

Username: django x2
Email: [email protected]
Password: something

Then on submit, the DB will be populated with

Username: django x2
Firstname: django
Lastname: x2
Email: [email protected]
Password: hashvalue

Alternatively, I guess it would be ok for a SQL timer job to come along and do that work (if Explode or a similar functions works in there).

TIA
 
Soldato
OP
Joined
28 Sep 2008
Posts
14,158
Location
Britain
Some interesting options.

To answer a few

1). There is no ambiguity on emails as fundamentally, the application will only ever return the firstname from the split string
2). That kind of answers the split(explode) at the period, because really, everything after the @ can be discarded
3). Our users are dumb, we'd get stupid Firstnames which would make identifying the user harder, so unless the form can dynamically fill in the firstname, but block it from being edited, then I would rather the user could not enter or choose a Firstname
 
Soldato
OP
Joined
28 Sep 2008
Posts
14,158
Location
Britain
$email = "[email protected]";
$firstname = explode(".", $email)[0];
$lastname = explode("@", explode(".", $email)[1])[0];
$username = $firstname . " " . $lastname;

Thanks, although the username is not their email address (without the domain) that's something different (confusing I know).

All that needs to happen is the DB fields need to populate a firstname and a lastname, even though the form doesn't explicitly ask for those. They are derived from the explode and inserted into the DB when the form is submitted.
 
Back
Top Bottom