Jump to content

Someone save me if you will?


Modernvox

Recommended Posts

Spent too many hours on this as it is, so I am reaching out for assistance. Somewhere in my code there is a statement causing the sending of email to the user to fail?

 

YOUR help greatly appreciated on this matter ::)

 

<?php 
  if (!$_POST['submit'] || !$_POST['name'] || !$_POST['state'] || !$_POST['city'] || !$_POST['email'] || !$_POST['username'] || !$_POST['password'] || !$_POST['confirm_password'] ) {
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" name= "register" method= "post">
<tr><td><font face= "arial" size= "2" color= "red">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp All fields required</font></td></tr><center><table>

<tr>    <td><b><font face= "arial" size= "3">FULL NAME</font></b></td>
<td><input type= "text" name= "name" size= "40" /></td>
</tr>
<tr>    <td><b><font face= "arial" size= "3">CITY</font></b></td>
<td><input type= "text" name= "city" size= "30" /></td>
</tr>
<tr>    <td><b><font face= "arial" size= "3">STATE</font></b></td>
<td><input type= "text" name= "state" size= "2" /></td>
</tr>
<tr>    <td><b><font face= "arial" size= "3">USERNAME</font></b></td>
<td><input type= "text" name= "username" size= "25" /></td>
</tr>
<tr>    <td><b><font face= "arial" size= "3">PASSWORD</font></b></td>
<td><input type= "password" name= "password" size= "25" /></td>
</tr>
<tr>    <td><b><font face= "arial" size= "3">CONFIRM PASSWORD</font></b></td>
<td><input type= "password" name= "confirm_password" size= "25" /></td>
</tr>
<tr>    <td><b><font face= "arial" size= "3">EMAIL</font></b></td>
<td><input type= "text" name= "email" size= "35" /></td>
</tr>
<tr>   <td><input type="hidden" name="form_submitted" value="1"/></td>
</tr>
</table></center>
<br><center><input type="submit" value= "Register" name="submit" /></center>
</form>
<?php
} else {

$name= $_POST['name'];
$state= $_POST['state'];
$city= $_POST['city'];
$email= $_POST['email'];
$username= $_POST['username'];
$password= $_POST['password'];
$confirm_password= $_POST['confirm_password'];

$errorlist= array();

    if (strlen($username) > 20 || strlen($username) <5){
$errorlist[] = "ERROR: <font face= \"tahoma\" color= \"red\" size= \"2\">Username must be between 5 and 25 characters long.</font>";
}
    if($password != $confirm_password){
$errorlist[] = "ERROR:<font face= \"tahoma\" color= \"red\" size= \"2\">Your passwords don't match, try again</font>";
}
if ($password == "" || strlen($password) <{
$errorlist[] = "ERROR: <font face= \"tahoma\" color= \"red\" size= \"2\">Password must be at least 8 characters long.</font>";
}
$pattern = '/^[a-z0-9]{4,}+.?([a-z0-9]+)?@([gmail]+\.)+[a-z]{3,4$/i'; 
//exclude Gmail here

if (preg_match($pattern, $email)){
$errorlist[] = "ERROR: <font face= \"tahoma\" color= \"red\" size= \"2\">Sorry, Gmail accounts not allowed</font>";
}

   $pattern = '/^[a-z0-9]{4,}+.?([a-z0-9]+)?@([a-z0-9]+\.)+[a-z]{3,4}$/i';
if (!preg_match($pattern, $email)) {
$errorlist[] = "ERROR: <font face= \"tahoma\" color= \"red\" size= \"2\">That's not a valid email</font>";
}

if (sizeof($errorlist) > 0) {
echo "Please review and correct the following errors: <br/>";
foreach ($errorlist as $e) {
echo "$e <br/>";
}
} else {
if (Form_submitted == "1") {
$activationKey =  mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand();

include("configclass.php");
$conn = mysql_connect($host, $dbuser, $password);
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname, $conn);

if (!get_magic_quotes_gpc()) {
$username = addslashes($username);
}
$usercheck = $username;
$check = mysql_query("SELECT username FROM members WHERE username = '$usercheck'")
or die(mysql_error());
$check2 = mysql_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, the username '.$username.' is already in use.');
}
//creates a 3 character sequence
function createSalt()
{
$string = md5(uniqid(rand(), true));
return substr($string, 0, 3);
}
$salt = createSalt();
$hash = sha1($salt . $hash);
$hash = sha1($password);


//sanitize username
$username = mysql_real_escape_string($username);

$query = "INSERT INTO members 
                            ( name,
                              city,
                              state,
                              username,
                              password, 
                              
                              email,
                              activationkey,
                              status
                               )
	              
                    VALUES 
                         ( '$name',
                           '$city',
                           '$state',
                           '$username',
                           '$password', 
                           
                           '$email',
                           '$activationKey',
                           '$verify' )";
mysql_query($query);


if (!empty($query)) {

echo "An email has been sent to $email . Please click on the verification link to register your new account";


//Send activation Email

$to      = $email;

$subject = " I Wanna JAM! Registration";

$message = "Verify your registration by clicking the following link:\rhttp://dezi9er.net16.net/process_registration.php?$activationKey\r\rRegards, I Wanna JAM! Team";

$headers = 'From: noreply@ IWannaJAM.com' . "\r\n" .

    'Reply-To: noreply@ IWannaJAM.com' . "\r\n" .

    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

} else {

echo "nothing here";
$queryString = $_SERVER['QUERY_STRING'];

$query = "SELECT * FROM members";

$result = mysql_query($query) or die(mysql_error());

  while($row = mysql_fetch_array($result)){

    if ($queryString == $row["activationkey"]){
echo "Thank You! Your registration has been verified and is now active. Welcome aboard! ";
$sql="UPDATE members SET activationkey = '', status='activated' WHERE (id = $row[id])";

       if (!mysql_query($sql))
        {
        die('Error: ' . mysql_error());
        }
mysql_close();
                }
             }
         }
      }
  }

}
?>

Link to comment
https://forums.phpfreaks.com/topic/193621-someone-save-me-if-you-will/
Share on other sites

There's a bit here that I've not seen used before, like putting an include 1/2 way through the script in an if statement...

 

and here: if

(Form_submitted == "1")

, I think you mean $Form_submitted (or $_POST['Form_submitted'] or $_Get['form_submitted'] depending on your php.ini settings and the form config...)

 

Also, if you change

mysql_query($query)

to

$result = mysql_query($query)

then you can also perform

$result = mysql_errno($result)

to get any errors that may be resulting from the mysql db entry attempt.

 

Just for this code, I'd also insert a few echo statements in each of the if & else loops, such as "Right now we're entering the if(state conditions) loop.  You can take them out once you figure out the problem, but this  helps you see exactly where the  program is executing....

There's a bit here that I've not seen used before, like putting an include 1/2 way through the script in an if statement...

 

and here: if

(Form_submitted == "1")

, I think you mean $Form_submitted (or $_POST['Form_submitted'] or $_Get['form_submitted'] depending on your php.ini settings and the form config...)

 

Also, if you change

mysql_query($query)

to

$result = mysql_query($query)

then you can also perform

$result = mysql_errno($result)

to get any errors that may be resulting from the mysql db entry attempt.

 

Just for this code, I'd also insert a few echo statements in each of the if & else loops, such as "Right now we're entering the if(state conditions) loop.  You can take them out once you figure out the problem, but this  helps you see exactly where the  program is executing....

 

Oh Man, that's right $_POST['form_submitted']    good eye, good eye

is the form POST or GET?  Make sure you've named it exactly as the submit button is named and that the value of the submit button is "1" and not "submit" since your code is expecting it to ==1.

 

 

Had Form_submitted instead of form_submitted

Thanks brother.

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.