title: Making a conditional statement to send email alert
body: <p>I'm trying to make a conditional statement to stop an email alert when the fail.php is called.  Right now I'm getting an email alert for both good and fail results.</p>
  
  <p>I do not want to receive an email if the the result failed.  Should I make two scripts or is there a way t make this work together?</p>
  
  <p>Thanks</p>
  
  <p>Here is the section I'm referring to along with the whole script.</p>
  
  <pre><code>if (mysql_affected_rows($result) &gt; 0) {
  mail($to, $subject, $msg, $headers);  
  $reg =          $_REQUEST['reg'] ; 
  $first_name =   $_REQUEST['first_name']; 
  header("location: reg_add_success.php?reg=" . urlencode($reg) . "&amp;first_name=" . urlencode($first_name)); 
  } 
  else { 
  header("location: reg_add_fail.php"); 
  exit(); // as sugested by John Conde
  }
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;?
  
  $to = 'newreg@41q.org';
  $subject = 'New Homeless Connection';
  $msg = "&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;New Homeless Connection&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;table cellspacing=\"0\" cellpadding=\"10\" border=\"1\" align=\"left\"&gt;
  &lt;tr&gt;
  &lt;td align=\"left\" width=\"150px\"&gt;Registery No.:&lt;/td&gt;
  &lt;td align=\"left\"&gt; $reg&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td align=\"left\"&gt;First Name:&lt;/td&gt;
  &lt;td align=\"left\"&gt;$first_name &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td align=\"left\"&gt;Connection Date:&lt;/td&gt;
  &lt;td align=\"left\"$&gt;$connect_date&lt;/td&gt;
  &lt;/tr&gt;
   &lt;tr&gt;
  &lt;td align=\"left\" colspan=\"2\"&gt;http://www.41q.org/admin/&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  ";
  
  // Make sure to escape quotes
  
  $headers  = 'MIME-Version: 1.0' . "\r\n";
  $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  $headers .= 'From: Homeless' . "\r\n";
  
  mail($to, $subject, $msg, $headers);
  
  date_default_timezone_set('America/Los_Angeles');
  $submit_date = date("m/d/y g:i A") ; 
  
  $order = "INSERT INTO reg_add (submit_date, 
  connect_date, 
  reg, 
  first_name, 
  )
  
  VALUES
  
  ('$submit_date',
  '$_POST[connect_date]', 
  '{$_POST[reg]}nv', 
  '$_POST[first_name]')";
  
  $result = mysql_query($order);
  
  if (mysql_affected_rows($result) &gt; 0) {
  mail($to, $subject, $msg, $headers);  
  $reg =          $_REQUEST['reg'] ; 
  $first_name =   $_REQUEST['first_name']; 
  header("location: reg_add_success.php?reg=" . urlencode($reg) . "&amp;first_name=" . urlencode($first_name)); 
  } 
  else { 
  header("location: reg_add_fail.php"); 
  exit(); // as sugested by John Conde
  }
  ?&gt;
  </code></pre>