Jump to content

Script not working when sending message


pcw

Recommended Posts

Hi, I have this script, it all works fine until it gets to the message sending point. What I want is if the $registerMail variable is set to yes then send the message and redirect user to login page, if not then just redirect the user to the login page.

 

However once registered, the user is sent to the login page and the message isnt sent.

 

<?php

include_once("data/server.php");

function decode_variable(&$siteName)
{
    $siteName = urldecode($siteName);
    $siteName = str_replace('%20',' ',$siteName); 
    return $siteName;
} 

decode_variable($siteName);

$registerMail = $_GET['regMail'];

$password1 = $_POST['password1'];
$password2 = $_POST['password2'];
// Get Posted Variables

$username = $_POST['username'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$address = $_POST['address'];
$town = $_POST['town'];
$county = $_POST['county'];
$postcode = $_POST['postcode'];
$email = $_POST['email'];
$approved = "no";
$IP = $_SERVER['REMOTE_ADDR'];

if ($password1 != $password2) {

echo "Your passwords did not match, please go back and register again";

} else {

// MySQL Connection

include_once("data/mysql.php");

$mysqlPassword = (base64_decode($mysqlpword));

$con = mysql_connect("$localhost", "$mysqlusername", "$mysqlPassword") or die(mysql_error());
mysql_select_db("$dbname", $con) or die(mysql_error());


$query = "SELECT COUNT(*) AS count FROM members WHERE username='$username'";
$results = mysql_query($query) or die ("Error reading from database");
$existingUsername = mysql_fetch_array($results);

if ($existingUsername['count'] > 0) {

echo "I'm sorry our database already contains that username please choose a new username to continue. ";

} else {

///// Check IP address does not belong to a unapproved user

$query = "SELECT COUNT(*) AS count FROM members WHERE IP='$IP' AND approved='$approved'";
$results = mysql_query($query) or die ("Error reading from database");
$bannedIP = mysql_fetch_array($results);

if ($bannedIP['count'] > 0) {
echo "I'm sorry your IP address has been banned from registering another account, please contact $adminEmail  ";

} else {

$sql = "INSERT INTO members (IP, username, firstname, lastname, address, town, county, postcode, email, password, approved)
VALUES
('$_SERVER[REMOTE_ADDR]','$_POST[username]','$_POST[firstname]','$_POST[lastname]','$_POST[address]','$_POST[town]','$_POST[county]','$_POST[postcode]','$_POST[email]','$_POST[password2]','$approved')";

mysql_query($sql,$con);
mysql_close($con);

}
}
}
///////////////// Send registration Mail ///////////////////////////

if ($registerMail == 'yes') {


$bodyReg = file_get_contents('data/registrationMail.php');

$to = "$email";
$subject = "Welcome to $siteName";
$body = "\nDear $firstname;\n$bodyReg\nUsername: $username\n Password: $password2;";
$headers = "From: $adminEmail\r\n" .
     "X-Mailer: php";
if (mail($to, $subject, $body, $headers)) {
echo "Registration Successful. You will be redirected to login in 5 seconds.";

?>

<meta http-equiv="REFRESH" content="5;url=../login.html">

<?php

}
} else {

echo "Registration Successful. You will be redirected to login in 5 seconds.";

?>

<meta http-equiv="REFRESH" content="5;url=../login.html">

<?php
}


?>

 

As always any help is much appreciated

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.