1

Topic: Use full name (firstname lastname) as username

Another syntax question from this non-PHP coder...

I'd like to use the full names of members as usernames, instead of the silly fantasy names people are forced to come up with.

I guess I have to add a line before this line in register.php:

$db->query('INSERT INTO users ...

I guess I have to add something like this (and remove a seperate username field from the form and elsewhere in the code):

$username = $firstname $lastname

But what would the right syntax be? And would that do the trick?

And would it mess up the system? I've found no problems with spaces and capitals in usernames.

Re: Use full name (firstname lastname) as username

It might be better to show the real name instead of the username where it's displayed.

3 (edited by Peter 2007-10-23 00:19)

Re: Use full name (firstname lastname) as username

elbekko wrote:

It might be better to show the real name instead of the username where it's displayed.

OK, thanks for the reply, but that's not what I meant, need or asked about.

I want to simplify the registration process and login process as much as possible, make it as transparant as possible. Full name and email address would be enough. Good riddance BS usernames.

Apart from that, my question is a coding/syntax question. If I want to do this, how should I do it? Would adding

$username = $firstname $lastname

with the correct syntax do the trick? What would the correct syntax be?

Please, can any PHP-er give me a pointer on the correct syntax so I can at least try?

Or is there a way to search for the correct PHP syntax of these things? When I put "$username=" in a search engine the markup elelements are ignored and I get only irrelevant results about "username".

Re: Use full name (firstname lastname) as username

No

$username = $firstname.$lastname;

That would be valid syntax, I couldn't say how well it would work.

5 (edited by Peter 2007-10-23 00:21)

Re: Use full name (firstname lastname) as username

Thanks again Smartys! I'll give this a try.

But how can I get a space between first and last name? Something like this:

$username = '.$firstname.' '.$lastname.';

6

Re: Use full name (firstname lastname) as username

The exact same way as in the answer you were given last time you asked this question.

http://punbb.org/forums/viewtopic.php?id=16844

7 (edited by Peter 2007-10-23 00:49)

Re: Use full name (firstname lastname) as username

MattF wrote:

The exact same way as in the answer you were given last time you asked this question.
http://punbb.org/forums/viewtopic.php?id=16844

I looked at that, but it's not the same thing, is it? In that case I wanted to output from the database. In that case you call the field with something like "firstname".

In this case I want to equate "$username" with "$firstname $lastname" to submit data into the database. It's not at all obvious to me that these would require the same syntax and there are still many variations possible from the solution on that link to this situation.

Anyway, Smartys solution allowed me to test the principle, but only the firstname was entered as username. Edit: My mistake again. Should have used surname instead of lastname.

The solution works for me. I had to remove checks for the username. They are no longer needed, because using the real name kinda builds some checks in.

But I still need to figure out the right syntax. I'll try some variations...

Probably this?

$username = $firstname.' '.$lastname;

Yes, that works! Nice. Thanks a lot for the pointers. It saved me a lot of time puzzling.

I like this solution. It really simplifies the registration - just name and email. Any downsides I'm overlooking?

8

Re: Use full name (firstname lastname) as username

$username = '\''.$db->escape($firstname.' '.$lastname).'\'';

9

Re: Use full name (firstname lastname) as username

MattF wrote:

$username = '\''.$db->escape($firstname.' '.$lastname).'\'';

Thanks again.

This worked as well:

$username = $firstname.' '.$lastname;

Does 'db->escape' have advantages?

10

Re: Use full name (firstname lastname) as username

Peter wrote:

Does 'db->escape' have advantages?

Not advantages, as such. It merely preps input for the db.

Re: Use full name (firstname lastname) as username

So if you're putting something into the database, it's needed for security reasons