PHP

If, for example, someone enters their full name in a text field, eg,
Billy McGeek, is it possible to filter out everything from the space
forward so only the first name gets passed to the session flash but
the full name still gets stored in the db? I know it would be simple
to accomplish by using separate “first” and “last” text fields
instead, I’m just curious to know if it’s possible.

Todd


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Sure, something along these lines should work:

// Split the name into an array of space separated words
$name = explode(" ", $_POST['name']);
// Store the first part of the name as a session variable (we assume there is only one word in the first name)
$_SESSION['firstName'] = name[0];

// Insert the original post data into the table
$query = 'INSERT INTO users (name) VALUES ("'.mysql_real_escape_string($_POST['name'].'")';

Of course someone with a first name that contains a space (John Paul, for instance) wouldn’t benefit from this so a first name field would ultimately be the best solution.

Joe

On 31 Mar 2011, at 18:02, Todd wrote:

If, for example, someone enters their full name in a text field, eg, Billy McGeek, is it possible to filter out everything from the space forward so only the first name gets passed to the session flash but the full name still gets stored in the db? I know it would be simple to accomplish by using separate “first” and “last” text fields instead, I’m just curious to know if it’s possible.

Todd


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options