Page 1 of 1

ways to check a value exists

Posted: Tue May 13, 2003 9:13 am
by deejay
this should be straight forward but somehow I can not get it to work. The problem must be in the condition I am using ( have tried several ways now) to ask whether a value is being passed for the query. When it finds an result it works fine, just when there's not a value there it passes through the function as if there is. Any help appreciated thanks.
Scroll down to the orange text for the bit at question.

Code: Select all

<?php
$query = "SELECT * FROM ccMembers WHERE user_from='$postcodeTown' && installer_approved='approved' ORDER BY user_id ASC ";

      $searchResults = mysql_query($query) or die('error making query');
      $resultRowCount = mysql_num_rows($searchResults);

       $resultRow = mysql_fetch_assoc($searchResults);

              $installerAddress = $resultRow['user_email'];
       $installerFirstName = $resultRow['firstName'];
       $installerLastName = $resultRow['lastName'];
       $installerCompanyName = $resultRow['company_name'];

      $installerEmailBody = 'Hi, Please contact '.$order->customer['firstname'].' '.$order->customer['lastname'].' either call them at '.$order->customer['telephone'].' or email them at '.$order->customer['email_address'].' about the order<br><br>'.$email_order. '<br><br>Please email CCTV-City at sales@cctv-city.com as soon initial contact with the customer is made. ';
      $installerTextSubject = 'CCTV-City.com order made in your area. ';


// THE FOLLOWING CONDITION IF WHAT DOES NOT WORK
// I HAVE TRIED SEVERAL WAYS OF RUNNING THIS CHECK

       if(!isset($installerAddress)) {

   $webMonitorTextSubject2 = 'An order has been made but there is no installer in that area ';

 $webMonitorEmailBody2 = 'The following order has been made but there is no installer in the area requested.<br><br>'.$email_order. '';

 tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, $webMonitorTextSubject2, nl2br($webMonitorEmailBody2), STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, '');
 }

       else    {
 tep_mail('', $installerAddress, $installerTextSubject, nl2br($installerEmailBody), STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, '');

 $webMonitorTextSubject = 'An order has been made and sent to installer ';

 $webMonitorEmailBody = 'Installer '.$installerFirstName.' '.$installerLastName.' from the company '.$installerCompanyName.' who can be contacted at '.$installerAddress.' has been informed of the order.<br><br>'.$email_order. '';

 tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, $webMonitorTextSubject, nl2br($webMonitorEmailBody), STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, '');


   }

 }
?>

Posted: Tue May 13, 2003 10:30 am
by volka
$installerAddress = $resultRow['user_email'];
...
if(!isset($installerAddress)) {
...
you might get an undefined index user_email warning but nevertheless $installerAddress is defined/set afterwards.
You have to check wether there was a record before you access its members.

Posted: Tue May 13, 2003 10:50 am
by deejay
hhmmm, there is no record that is being return (or shouldn't be) firstly I have checked the database that i am pulling the information from and secondly i get an email sent that does not print any of the values that would be in the returned string.

I have moved on to something else for the moment but will read the link you sent me and then reconsider my script, hopefully then I will try and make a little sense of what i'm trying to explain.

Thanks

Deej

Posted: Wed May 14, 2003 2:56 am
by deejay
my script now works, although I haven't changed anything :?: i think my computer is playing games with my head.

Volka ,

thanks for the link though, a good read. beleive it or not i do try many other means before i get to this board and I very much appreciate the help given here by you all, after all i realise from most of my posts I look like I've been on the stupid pills.

Cheers :)

Posted: Wed May 14, 2003 3:40 am
by volka
the link is just my signature ;)