Need help with some small code please

hello guys im fairly new to php.
I am making a login logout register system…

so far i have made the login and logout parts which work…

but i have made the register part which does work until you register . the problem im having is when i make a new account (testing to make sure it works and what not) it registers the person but does NOT send the activation email, so this is my problem//

if anyone can help me i would be thankful and can put the code up.

Thanks :smiley:

Firstly: Check that your hosting allows you to send mail. If not then find a new host. Personally you could try my own web-host run by me at raythwebs.info which allows send mail.

Secondly: do you have error checking on? If not, turn it on and report any errors.

Third: It helps if we see your code to make sure you’re doing it correctly.

my hosting alows it :slight_smile:

  1. im not sure.

Here is the code…

[code]<?php

error_reporting (E_ALL ^ E_NOTICE);

?>

Register <?php

if ( $_POST[‘registerbtn’] ){
$getuser = $_POST[‘user’];
$getemail = $_POST[‘email’];
$getpass = $_POST[‘pass’];
$getretypepass = $_POST[‘retypepass’];

if ($getuser){
	if ($getemail){
		if ($getpass){
			if ($getretypepass){
				if ( $getpass === $getretypepass ){
					if ( (strlen($getemail) >= 7) && (strstr($getemail, "@")) && (strstr($getemail, "@")) ){
						require("./connect.php");
						
						$query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
						$numrows = mysql_num_rows($query);
						if ($numrows == 0){
							$query = mysql_query("SELECT * FROM users WHERE email='$getemail'");
							$numrows = mysql_num_rows($query);
							if ($numrows == 0){
								
								$password = md5 (md5("Hfke857".$password."Hjs84jf"));
								$date = date ("F d, Y");
								$code = md5(rand());
								
								mysql_query("INSERT INTO users VALUES (
									'', '$getuser', '$password', '$getemail', '0', '$code', '$date' 
								)");
								
								$query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
								$numrows = mysql_num_rows($query);
								if ($numrows == 1){
									
									$site = "http://www.motorbikecentral.com";
									$webmaster = "Motor Bike Central Team<[email protected]>";
									$headers = "From: $webmaster";
									$subject = "Activate Your Account";
									$message = "Thankyou for registering with motorbikecentral.com. Click the link below to acctivate your account.\n";
									$message .= "$site/activate.php?user=$getuser&code=$code\n";
									$message .= "You must activate your account to login.";
									
									if ( mail($getmail, $subject, $message, $headers) ){
										$errormsg = "You have been registered. You must activate your account from the activation link sent to <b>$getemail</b>";
										$getuser = "";
										$getemail = "";
									}
									else
										$errormsg = "An error has occured. Your activation email was not sent.";
									
								}
								else
									$errormsg = "An error has occured. Your account was not created.";
								
							}
							else
								$errormsg = "There is already a user with that email.";
						}
						else
							$errormsg = "There is already a user with that username.";
						
						mysql_close();
					}
					else
						$errormsg = "You must enter a valid email address to register.";
				}
				else
					$errormsg = "Your passwords did not match.";
			}
			else
				$errormsg = "You must retype your password to register.";
		}
		else
			$errormsg = "You must enter your password to register.";
	}
	else
		$errormsg = "You must enter your email to register.";
}
else
	$errormsg = "You must enter your username to register.";

}

$form = "

$errormsg
Username:
Email:
Password:
Retype Password:
";

echo $form;

?>

[/code]

OpzMaster: Added CODE blocks around the code for ease of debugging.

Ok for long codes such as that please use the [ code] tags as it makes it easier to read.

Now:

Use ini_set('display_errors', 'On'); error_reporting(-1); instead of

error_reporting (E_ALL ^ E_NOTICE);

okay i got this message after changing that code…

Strict Standards: main() [function.main]: It is not safe to rely on the system’s timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Chicago’ for ‘CST/-6.0/no DST’ instead in /home/motorbik/public_html/register.php on line 17

Notice: Undefined index: registerbtn in /home/motorbik/public_html/register.php on line 17

Strict Standards: main() [function.main]: It is not safe to rely on the system’s timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Chicago’ for ‘CST/-6.0/no DST’ instead in /home/motorbik/public_html/register.php on line 108

Notice: Undefined variable: errormsg in /home/motorbik/public_html/register.php on line 108

Strict Standards: main() [function.main]: It is not safe to rely on the system’s timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Chicago’ for ‘CST/-6.0/no DST’ instead in /home/motorbik/public_html/register.php on line 112

Notice: Undefined variable: getuser in /home/motorbik/public_html/register.php on line 112

Strict Standards: main() [function.main]: It is not safe to rely on the system’s timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Chicago’ for ‘CST/-6.0/no DST’ instead in /home/motorbik/public_html/register.php on line 127

Notice: Undefined variable: getemail in /home/motorbik/public_html/register.php on line 127

Ok add the following to the top of your code under the error reporting part:

date_default_timezone_set('America/Chicago');

Change the America/Chicago to something that will work. See http://uk.php.net/date_default_timezone_set for more info.

As for the other errors, those are expected as you are automatically checking for $_POST[‘registerbtn’]. Try using isset($_POST[‘registerbtn’]) instead.

okay this is what i get now…

Notice: Undefined index: registerbtn in /home/motorbik/public_html/register.php on line 18

Notice: Undefined variable: errormsg in /home/motorbik/public_html/register.php on line 109

Notice: Undefined variable: getuser in /home/motorbik/public_html/register.php on line 113

Notice: Undefined variable: getemail in /home/motorbik/public_html/register.php on line 128

then when i try make a new user i get these…

Notice: Undefined variable: password in /home/motorbik/public_html/register.php on line 39

Notice: Undefined variable: getmail in /home/motorbik/public_html/register.php on line 59

The first 4 errors I would expect as you seem to be trying to load the variables all the time whether the form has been filled in or not. The last 2 suggest that the $_POST information isn’t being passed through

okay is there a way i can fix them?

Can you post your current code (all of it)

Sure thing…

[php]

<?php ini_set('display_errors', 'On'); error_reporting(-1); date_default_timezone_set('Australia/South'); ?> Register <?php

if ($_POST[‘registerbtn’]){
$getuser = $_POST[‘user’];
$getemail = $_POST[‘email’];
$getpass = $_POST[‘pass’];
$getretypepass = $_POST[‘retypepass’];

if ($getuser){
	if ($getemail){
		if ($getpass){
			if ($getretypepass){
				if ( $getpass === $getretypepass ){
					if ( (strlen($getemail) >= 7) && (strstr($getemail, "@")) && (strstr($getemail, "@")) ){
						require("./connect.php");
						
						$query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
						$numrows = mysql_num_rows($query);
						if ($numrows == 0){
							$query = mysql_query("SELECT * FROM users WHERE email='$getemail'");
							$numrows = mysql_num_rows($query);
							if ($numrows == 0){
								
								$password = md5 (md5("Hfke857".$password."Hjs84jf"));
								$date = date ("F d, Y");
								$code = md5(rand());
								
								mysql_query("INSERT INTO users VALUES (
									'', '$getuser', '$password', '$getemail', '0', '$code', '$date' 
								)");
								
								$query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
								$numrows = mysql_num_rows($query);
								if ($numrows == 1){
									
									$site = "http://www.motorbikecentral.com";
									$webmaster = "Motor Bike Central Team<[email protected]>";
									$headers = "From: $webmaster";
									$subject = "Activate Your Account";
									$message = "Thankyou for registering with motorbikecentral.com. Click the link below to acctivate your account.\n";
									$message .= "$site/activate.php?user=$getuser&code=$code\n";
									$message .= "You must activate your account to login.";
									
									if ( mail($getmail, $subject, $message, $headers) ){
										$errormsg = "You have been registered. You must activate your account from the activation link sent to <b>$getemail</b>";
										$getuser = "";
										$getemail = "";
									}
									else
										$errormsg = "An error has occured. Your activation email was not sent.";
									
								}
								else
									$errormsg = "An error has occured. Your account was not created.";
								
							}
							else
								$errormsg = "There is already a user with that email.";
						}
						else
							$errormsg = "There is already a user with that username.";
						
						mysql_close();
					}
					else
						$errormsg = "You must enter a valid email address to register.";
				}
				else
					$errormsg = "Your passwords did not match.";
			}
			else
				$errormsg = "You must retype your password to register.";
		}
		else
			$errormsg = "You must enter your password to register.";
	}
	else
		$errormsg = "You must enter your email to register.";
}
else
	$errormsg = "You must enter your username to register.";

}

$form = "

$errormsg
Username:
Email:
Password:
Retype Password:
";

echo $form;

?>

[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service