Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Quick Formatting Question


myztic_man

Recommended Posts

Posted

Hey all.

I am relatively new to PHP so this may seem like a bit of a n00b question - however I have some experience in Java, C and C++ so it's more syntax issues than anything else.

 

I have a 'subscribe to our newsletter' box on the Right Hand side of our store (www.glowsticksltd.co.nz)

The box asks for two things, e-mail address and name.

 

At the moment, name is simply taken in via the command (this is in includes/boxes/newsletter.php)

<br>' . TEXT_NAME . '<br><input type="text" name="name" value="" checked size="15" maxlength="35">'

 

And it's then shoved into the database via the command (this is in root/newsletter_subscribers.php)

tep_db_query("insert into " . TABLE_SUBSCRIBERS . " (subscribers_email_address, subscribers_firstname, language, subscribers_email_type, date_account_created, customers_newsletter, subscribers_blacklist, hardiness_zone, status_sent1, source_import) values ('" . strtolower($HTTP_POST_VARS['Email']) . "', '" . ucwords(strtolower($HTTP_POST_VARS['name'])) . "', 'English', '" . $HTTP_POST_VARS['email_type'] . "', now() , '1', '0', '" . $domain4 . "', '1', 'subscribe_newsletter')");

 

I am wanting a piece of code which will check whether the name given is a first and last name (ie: two words seperated by a space).

I then need the code to split them (on either side of the space) and assign the first one to be $firstname and the second one to be $lastname

 

If anyone could help me it would be much appreciated.

Posted

Something like this:

 

<?php

$full_name = ucwords(strtolower($HTTP_POST_VARS['name']));

// look for the separating space
if ( strstr( $full_name , " " ) ) {
 $pieces = explode(" ", $full_name); // found it, split the string there
 $firstname = $pieces[0];  // first name = first piece
 $lastname = $pieces[1];  // last name = second piece
} else {
 $firstname = $full_name; // no separating space was found
}
?>

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...