Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Easy PHP Coding Question!


Becki

Recommended Posts

Hi,

I'm trying to get this code to work. I am basically checking whether an email address exists in a customer table and a subscribers table. The logic I want is,

 

If in customer table

>>>No - If in subscribers

>>>>>>No - Insert

>>>>>>Yes - Update

>>>Yes - Update customers table

End

 

Is the if statement along the right lines or do I need elseif? Many thanks for any help :)

 

P.S i adapted this code from somewhere to add in the check for customers table - I hope it is safe to do so?

 

Oh and also is there a function to split a string (by a space) into two, I.e. 'Joe Bloggs' to 'Joe' and 'Bloggs'

 

  $subscribers_info = tep_db_query("select subscribers_id from " . TABLE_SUBSCRIBERS . " where subscribers_email_address = '" . $HTTP_POST_VARS['Email'] . "' ");
 $customer_exist_news = tep_db_query("select customers_id from customers WHERE customers_email_address = '" . $HTTP_POST_VARS['Email'] . "' ");

$date_now = date('Ymd');

 if (!tep_db_num_rows($customer_exist_news)) {
  if (!tep_db_num_rows($subscribers_info)) {
   tep_db_query("insert into " . TABLE_SUBSCRIBERS . " (subscribers_email_address, subscribers_lastname, 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['lastname'])) . "',  'English',  'HTML',  now() ,  '1',  '0', '" . $domain4 . "', '1', 'subscribe_newsletter')");
  	} else {
	 tep_db_query("update " . TABLE_SUBSCRIBERS . " set customers_newsletter = '" . '1' . "', subscribers_email_type = '" . $HTTP_POST_VARS['email_type'] . "'  where subscribers_email_address  = '" . $HTTP_POST_VARS['Email'] . "' ");
  } else {
tep_db_query("UPDATE customers SET customers_newsletter = '1' WHERE customers_email_address = '" . $HTTP_POST_VARS['Email'] . "'");
}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...