Php operators

thank u Guido for the advice but b4 I go any further would you kindly check my brackets ?
i’m a newbie with php
ta

They look fine to me. You aren’t getting any errors, are you?

 exit();     }   

should there be a bracket here ? it is the OUTER IF statement

ta

Yes, it closes the outer if, and is followed by the outer else. I’d put it on the next line for readability:


if( ! in_array($answer, array(4, 'four'))) 
{  // opening outer if  
       //if answer is not in an array containing either 4 or four then.. 
        echo "You have entered the security question incorrectly. Your request will NOT be processed"; 
        exit();     
}  // closing outer if
else 
{  // opening outer else
    if ($from != "") 
    {   // opening inner if
            //test send mail to Melanie  
            mail($to, $subject, $contents, $from_header); 

            // redirect back to url visitor came from 
            $display_blockmsg = "Thank you, <b>$_POST[title] $_POST[firstname] $_POST[lastname]</b>, <br> 
                                Your contact form details have been sent to us <br> 
                                Your contact details are:<br><br> 
                                <b>Address:</b> $_POST[address1]  
                                $_POST[address2],<br> 
                                <b>City:</b> $_POST[city]<br> 
                                <b>County:</b> $_POST[county]<br> 
                                <b>Postcode:</b> $_POST[postcode]<br> 
                                <b>Country:</b> $_POST[country]<br> 
                                <b>Telephone:</b> $_POST[telephone]<br> 
                                <b>email:</b> $_POST[from]<br><br>";         
  }  // closing inner if
  else       
  {  // opening inner else    
      $display_blockmsg = "<center><b>The email field</b> is empty. Please go back and complete this field.</center>";  
  }  // closing inner else
} // closing outer else  

Thanks so much for this Guido
I appear to be learning PHP the hard way !

In C language the if…else statements brackets are different …

can i get back to you later about this …

Of course. And if I’m not around, someone else surely will be here to answer your questions.

@newhere

I don’t know what editor of platform you use but here are a couple of handy PHP debugging tips:



   define('jj', '<br />'); # easier than typing '<br />; 

   define('LOCALHOST', 'localhost' == $_SERVER['SERVER_NAME']; # handy for following

  if( LOCALHOST )
  {
     echo jj, 'This line will only show on http://localhost/'; 
  }
  

  echo jj, __LINE__; 
  echo jj, __FILE__;
  echo jj, __METHOD__;

  die; # stops program execution and when remmed or deleted program continues

 
  $a = array('Tom', 'Dick', 'Harry', 'Susan');
  echo '<pre>';
     print_r( $a );  # formats with line feeds
  echo '</pre>';

  echo '<pre>';
     var_dump( $a );  # verbose version
  echo '</pre>';


Any more handy tips?

Always capitalise constants? :wink:

HI
thanks to this very helpful thread :
http://www.sitepoint.com/forums/showthread.php?768872-Common-PHP-Problems

i put this code

ini_set(‘display_errors’,1);
error_reporting(E_ALL);

at the top of my php file and it deduced that it was an undeclared variable that was causing problems…and nothing to do with my IF statements
Thanks for your help guys

I just wondered if you had any comments about PHP form security ?
I have put :

whoops pressed the submit button too early !
i put this code

<?php
while (@ob_end_flush());
?>

at the end of my php - is that enough to get rid of all variable values ?

Of course when the user has input all the information into a html form on screen he/she can press back button to see it all again but what else to do to ensure security ?
can you suggest anything please ?
Thanks !
M