Registration form help

Hi Guys,

This is really stumping me here lol i have set my registration page code to email me when a user signs up (once its entered in the database)

code:


<?php
if (isset($_POST['submitSignUp']))
{
   // Errors array()
   $errors = array();

   // POST vars
   $fName = mysql_real_escape_string($_POST['fname']);
   $lName = mysql_real_escape_string($_POST['lname']); 
   $email = mysql_real_escape_string($_POST['email']); 
   $pass1 = mysql_real_escape_string($_POST['pass1']); 
   $pass2 = mysql_real_escape_string($_POST['pass2']); 
   $cntry = mysql_real_escape_string($_POST['cntry']); 
   
   // Does passwords match
   if ($pass1 != $pass2)
   {
      $errors[] = "Your passwords don't match."; 
   }
   
   // Potential errors 
   // Empty fields
   if (empty($fName) || empty($lName) || empty($email) || empty($pass1) || empty($pass2)) { 
        $errors[] = "You never filled in all the fields."; 
   } else {
    
       // Does user exist? 
       $result = mysql_query("SELECT * FROM `dig_customers` WHERE `email`='$email' LIMIT 1"); 
       if (mysql_num_rows($result) > 0) {    
          $errors[] = "The e-mail address <b>$email</b> has already been registered.";  
       } else {

       // Empty for now...

       }
   }  
   
   // display errors if any exist
   if (count($errors) > 0) 
   { 
       print "<div id=\\"errorMsg\\"><h3>Ooops! There was error(s)</h3><ol>"; 
       foreach($errors as $error) 
       { 
          print "<li>$error</li>"; 
       }
       print "</ol></div>";
   } else {
       print "<div id=\\"okMsg\\"><p>All done :) you can now sign in.</p></div>";
       
         // Encrypt the password before insertion
         $encPass = md5($pass1);

         // Insert into the database
         $q = mysql_query("INSERT INTO `dig_customers` 
         
         (`id`,
          `password`,
          `password_unencrypted`,
          `gender`,
          `title`,
          `first_name`,
          `last_name`,
          `address`,
          `city`,
          `state_county`,
          `post_zip_code`,
          `country`,
          `email`,
          `home_number`,
          `mobile_number`,
          `news_letter`,
          `special_offers`,
          `admin_level`,
          `registered`) 
         
           VALUES 
          
          ('',
          '$encPass',
          '$pass1',
          'NULL',
          'NULL',
          '$fName',
          '$lName',
          'NULL',
          'NULL',
          'NULL',
          'NULL',
          '$cntry',
          '$email',
          'NULL',
          'NULL',
          'NULL',
          'NULL',
          'N',
           NOW())");

          if ($q)
          {

            // Alert on signup
            send_graham_email("User Has Signed Up!");
          
          }
       
   }

}
?>

When i do a test signup on: http://www.digicures.com/sign-up.php everything works great i get an email and the entry is saved in the database, over the paste week or so i have had about 8 emails saying people have signed up but when i check the database there nothing there!

i can’t understand it, only when the insert query is true should it send me the mail eh?

can anyone see any problems with the code at all?

cheers guys

Graham

False alarm, type in the wrong password :rolleyes: Silly me, I need more coffee. :coffee:

It could be the way you have done the email script, try this as I know it works fine for me, see if it helps:


function send_graham_email($actionTaken)
{
$to = "graham23s@xxx.com";
$subject = '$actionTaken';

$headers = "From: Digicures <info@digicures.com>\\r\
"; 
$headers = "To: Admin <".$to.">\\r\
"; 
$headers = "Reply-To: Digicures <info@digicures.com>\\r\
"; 
$headers = "Return-Path: <info@digicures.com>\\r\
";
$headers = "MIME-Version: 1.0\\r\
";
$headers = "Content-Type: text/plain; charset=utf-8\\r\
";
$headers .= "Content-Transfer-Encoding:  8bit\\r\
\\r\
";

$msg .= "$actionTaken

Regards
Admin

http://www.digicures.com

This is an automated response, please do not reply to this email!";

$email = mail($to, $subject, $msg, $headers);
return $email;
}

Hi Spence,

Really? i tried to login using your test credentials an dit logged in fine, did you use: username: [email] and password: [your password]?

cheers mate

Graham

I just like to point out that I was not able to login after registering.

Hi Guys,

Thanks got the reply, that code was really the nuts and bolts of it but heres the rest:


&lt;?php
session_start(); 
include("inc/inc-dbconnection.php");
include("inc/inc-online.php");
include("inc/inc-functions.php");
include("inc/inc-arrays.php");
include("inc/inc-header.php");
?&gt;
&lt;div class="fcs-main-content-area"&gt;	
 &lt;div class="fcs-breadcrumb"&gt;
  &lt;ul&gt;
	 &lt;li&gt;&lt;a href="index.php"&gt;Home&lt;/a&gt;&lt;/li&gt; »
	 &lt;li&gt;&lt;a href="javascript:history.go(-1)"&gt;Previous Page&lt;/a&gt;&lt;/li&gt; »
	 &lt;li&gt;&lt;b&gt;Sign up for an account&lt;/b&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/div&gt;

&lt;FORM class="uniForm" method="POST" action="sign-up.php"&gt;
&lt;?php
if (isset($_POST['submitSignUp']))
{
   // Errors array()
   $errors = array();

   // POST vars
   $fName = mysql_real_escape_string($_POST['fname']);
   $lName = mysql_real_escape_string($_POST['lname']); 
   $email = mysql_real_escape_string($_POST['email']); 
   $pass1 = mysql_real_escape_string($_POST['pass1']); 
   $pass2 = mysql_real_escape_string($_POST['pass2']); 
   $cntry = mysql_real_escape_string($_POST['cntry']); 
   
   // Does passwords match
   if ($pass1 != $pass2)
   {
      $errors[] = "Your passwords don't match."; 
   }
   
   // Potential errors 
   // Empty fields
   if (empty($fName) || empty($lName) || empty($email) || empty($pass1) || empty($pass2)) { 
        $errors[] = "You never filled in all the fields."; 
   } else {
    
       // Does user exist? 
       $result = mysql_query("SELECT * FROM `dig_customers` WHERE `email`='$email' LIMIT 1"); 
       if (mysql_num_rows($result) &gt; 0) {    
          $errors[] = "The e-mail address &lt;b&gt;$email&lt;/b&gt; has already been registered.";  
       } else {

       // Empty for now...

       }
   }  
   
   // display errors if any exist
   if (count($errors) &gt; 0) 
   { 
       print "&lt;div id=\\"errorMsg\\"&gt;&lt;h3&gt;Ooops! There was error(s)&lt;/h3&gt;&lt;ol&gt;"; 
       foreach($errors as $error) 
       { 
          print "&lt;li&gt;$error&lt;/li&gt;"; 
       }
       print "&lt;/ol&gt;&lt;/div&gt;";
   } else {
       print "&lt;div id=\\"okMsg\\"&gt;&lt;p&gt;All done :) you can now sign in.&lt;/p&gt;&lt;/div&gt;";
       
         // Encrypt the password before insertion
         $encPass = md5($pass1);

         // Insert into the database
         $q = mysql_query("INSERT INTO `dig_customers` 
         
         (`id`,
          `password`,
          `password_unencrypted`,
          `gender`,
          `title`,
          `first_name`,
          `last_name`,
          `address`,
          `city`,
          `state_county`,
          `post_zip_code`,
          `country`,
          `email`,
          `home_number`,
          `mobile_number`,
          `news_letter`,
          `special_offers`,
          `admin_level`,
          `registered`) 
         
           VALUES 
          
          ('',
          '$encPass',
          '$pass1',
          'NULL',
          'NULL',
          '$fName',
          '$lName',
          'NULL',
          'NULL',
          'NULL',
          'NULL',
          '$cntry',
          '$email',
          'NULL',
          'NULL',
          'NULL',
          'NULL',
          'N',
           NOW())");

          if ($q)
          {

            // Alert on signup
            send_graham_email("User Has Signed Up!");
          
          }
       
   }

}
?&gt;
&lt;FIELDSET&gt;
&lt;DIV class=ctrlHolder&gt;&lt;LABEL for=""&gt;First Name&lt;/LABEL&gt; &lt;INPUT class=textInput size=35 type=text name="fname"&gt; 
&lt;P class=formHint&gt;&nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;DIV class=ctrlHolder&gt;&lt;LABEL for=""&gt;Second Name&lt;/LABEL&gt; &lt;INPUT class=textInput size=35 type=text name="lname"&gt; 
&lt;P class=formHint&gt;&nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;DIV class=ctrlHolder&gt;&lt;LABEL for=""&gt;Email Address&lt;/LABEL&gt; &lt;INPUT class=textInput size=35 type=text name="email"&gt; 
&lt;P class=formHint&gt;&nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;DIV class=ctrlHolder&gt;&lt;LABEL for=""&gt;Password&lt;/LABEL&gt; &lt;INPUT class=textInput size=35 type=text name="pass1"&gt; 
&lt;P class=formHint&gt;&nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;DIV class=ctrlHolder&gt;&lt;LABEL for=""&gt;Confirm Password&lt;/LABEL&gt; &lt;INPUT class=textInput size=35 type=text name="pass2"&gt; 
&lt;P class=formHint&gt;&nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;DIV class=ctrlHolder&gt;&lt;LABEL for=""&gt;Country&lt;/LABEL&gt; &lt;SELECT name="cntry"&gt;&lt;?php foreach($countryArray as $country) { print "&lt;option value=\\"$country\\"&gt;$country&lt;/option&gt;"; } ?&gt;&lt;/SELECT&gt; 
&lt;P class=formHint&gt;&nbsp;&lt;/P&gt;&lt;/DIV&gt;
&lt;DIV class=buttonHolder&gt;&lt;BUTTON class=primaryAction name="submitSignUp" type=submit&gt;Sign Up!&lt;/BUTTON&gt;&lt;/DIV&gt;&lt;/FIELDSET&gt; &lt;/FORM&gt;

&lt;?php
include("inc/inc-footer.php");
?&gt;

the function looks like:


function send_graham_email($actionTaken)
{
    $to      = "graham23s@xxx.com";
    $subject = "$actionTaken";
    $from    = "info@digicures.com";
    $body    = "&lt;br /&gt;";
    $body .= "$actionTaken";
    $body .= "&lt;br /&gt;&lt;br /&gt;";
    $body .= "Regards &lt;br /&gt;&lt;a href=\\"http://www.digicures.com\\"&gt;http://www.digicures.com&lt;/a&gt;";
    $headers = "MIME-Version: 1.0\\r\
";
    $headers .= "From: digicures.com&lt;$from&gt;\
";
    $headers .= "Content-type: text/html; charset=iso-8859-1\\r\
";
    $mail = mail($to, $subject, $body, $headers);
    return $mail;
}

spence noodle and someone else signed up with no probs, but still 1 email got through thatwas in the database.

cheers guys

Graham

You maybe better off with something like this for your email part:


if (!$q) {
    die('Invalid query: ' . mysql_error());
}else{
   // Alert on signup 
   send_graham_email("User Has Signed Up!");
}

But as what kalon has said we don’t know what the script looks like for the email function.

if ($q) 
          { 
 
            // Alert on signup 
            send_graham_email("User Has Signed Up!"); 
 
[FONT=Courier New][COLOR=#007700]         }[/COLOR][/FONT]

For the function to run then $q has evaluated to true and the insert was sucessful.

So obviously the problem must be either in the send_graham_email() function or further downstream in your code, neither of which you have posted.

Your mysql query looks fine but without looking at the rest of the code I can only gues you have not included the login details for the database connection. Either inlcude it by file:


include_once('config.inc.php');

or by code:


// database settings
    $host = "something.com";
    $user = "username_for_database";
    $pass = "password_for_database";
    $db   = "database_name";
    
    $mysql_link=mysql_connect ($host, $user, $pass, TRUE) 
    or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ( $db );