Jump to content

[SOLVED] Return not working


Recommended Posts

class

class member
{
function register($username, $password, $name, $email, $admin=0)
{
	$query = mysql_query("SELECT * FROM `users` WHERE `username`='$username' OR `email`='$email'");
	$unique = mysql_num_rows($query);
	if (empty($username) || empty($password) || empty($name) || empty($email) || strlen($password) < 6)
	{
		$return = "All fields must be filled out and your password must be at least 6 characters in length. Please ensure everything is correct and try again.";
	}
	elseif ($unique > 0)
	{
		$return = "The username or email address you supplied is already in use by another member. Please try again";
	}
	else
	{
		$sql = "INSERT INTO `users` (`username`, `password`, `name`, `email`, `ip`, `admin`) VALUES ('$username', '". md5($password) ."', '$name', '$email', '". $_SERVER['REMOTE_ADDR'] ."', '-1')";
		$query = mysql_query($sql);
		if ($query)
		{
			// Get the user_id
			$id = mysql_insert_id();

			// Generate their md5 hash key
			$key = $this->generate_key(6);

			// Build the key string
			$key_string = "key=$key&id=$id";

			// Insert key into the database
			$sql = "INSERT INTO `keys` (`user_id`, `key`) VALUES ('$id', '$key')";
			$query = mysql_query($sql);

			// Send the account activation email
			$subject = "Account Activation At" . SITE_NAME;
			$message = 'Your account has successfully been created!  Please click the link below to activate your account and
			verify your email address is correct:' . SITE_URL . '/users/activate.php?key=' . $key_string;
			$from = "From: staff@". EMAIL_URL;
			mail ($email, $subject, $message, $from);

			$return = 'Thank you for registering with ' . SITE_NAME . '! In order to activate your account, you must verify
			the email that you supplied during the registration process. We have sent the email to ' . $email . ' with a link
			to activate your account. Once clicked, your account will become active.';
		}
		else
		{
			$return = "An error occured during the registration process. Please try again in a few minutes as the server could
			be busy at this moment. If this problem continues, please contact support.";
		}
		return $return;
	}
}
}

 

file where class/function is called

	$username = htmlentities(mysql_real_escape_string($_POST['username']));
	$password = htmlentities(mysql_real_escape_string($_POST['password']));
	$name = htmlentities(mysql_real_escape_string($_POST['name']));
	$email = htmlentities(mysql_real_escape_string($_POST['email']));

	$member->register($username, $password, $name, $email);

	echo $return;

 

it won't echo out $return.  It is like the variable isn't there.  :-/ am i missing something?

Link to comment
https://forums.phpfreaks.com/topic/59968-solved-return-not-working/
Share on other sites

See the added comments at the bottom of the code:

<?php

class member
{
function register($username, $password, $name, $email, $admin=0)
{
	$query = mysql_query("SELECT * FROM `users` WHERE `username`='$username' OR `email`='$email'");
	$unique = mysql_num_rows($query);
	if (empty($username) || empty($password) || empty($name) || empty($email) || strlen($password) < 6)
	{
		$return = "All fields must be filled out and your password must be at least 6 characters in length. Please ensure everything is correct and try again.";
	}
	elseif ($unique > 0)
	{
		$return = "The username or email address you supplied is already in use by another member. Please try again";
	}
	else
	{
		$sql = "INSERT INTO `users` (`username`, `password`, `name`, `email`, `ip`, `admin`) VALUES ('$username', '". md5($password) ."', '$name', '$email', '". $_SERVER['REMOTE_ADDR'] ."', '-1')";
		$query = mysql_query($sql);
		if ($query)
		{
			// Get the user_id
			$id = mysql_insert_id();

			// Generate their md5 hash key
			$key = $this->generate_key(6);

			// Build the key string
			$key_string = "key=$key&id=$id";

			// Insert key into the database
			$sql = "INSERT INTO `keys` (`user_id`, `key`) VALUES ('$id', '$key')";
			$query = mysql_query($sql);

			// Send the account activation email
			$subject = "Account Activation At" . SITE_NAME;
			$message = 'Your account has successfully been created!  Please click the link below to activate your account and
			verify your email address is correct:' . SITE_URL . '/users/activate.php?key=' . $key_string;
			$from = "From: staff@". EMAIL_URL;
			mail ($email, $subject, $message, $from);

			$return = 'Thank you for registering with ' . SITE_NAME . '! In order to activate your account, you must verify
			the email that you supplied during the registration process. We have sent the email to ' . $email . ' with a link
			to activate your account. Once clicked, your account will become active.';
		}
		else
		{
			$return = "An error occured during the registration process. Please try again in a few minutes as the server could
			be busy at this moment. If this problem continues, please contact support.";
		}
		return $return; // ==> MOVE THIS LINE DOWN
	}
	// ==> TO HERE
}
}

?>

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.