steelmanronald06 Posted July 14, 2007 Share Posted July 14, 2007 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 More sharing options...
Psycho Posted July 14, 2007 Share Posted July 14, 2007 Well, it looks to me that the return in your class is inside the last else clause. So if the first two conditions are true, then the $return value is never returned! Move the return in your class after the next closing curly brace. Link to comment https://forums.phpfreaks.com/topic/59968-solved-return-not-working/#findComment-298263 Share on other sites More sharing options...
Psycho Posted July 14, 2007 Share Posted July 14, 2007 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 } } ?> Link to comment https://forums.phpfreaks.com/topic/59968-solved-return-not-working/#findComment-298265 Share on other sites More sharing options...
steelmanronald06 Posted July 14, 2007 Author Share Posted July 14, 2007 I moved it out of the else, but i still get nothing. I even renamed it from $return to $body thinking that perhaps $return wasn't working because the return function already exists in PHP, but it didn't work neither. Link to comment https://forums.phpfreaks.com/topic/59968-solved-return-not-working/#findComment-298266 Share on other sites More sharing options...
lur Posted July 14, 2007 Share Posted July 14, 2007 $return = $member->register($username, $password, $name, $email); echo $return; ? Link to comment https://forums.phpfreaks.com/topic/59968-solved-return-not-working/#findComment-298269 Share on other sites More sharing options...
steelmanronald06 Posted July 14, 2007 Author Share Posted July 14, 2007 that worked! thanks! Link to comment https://forums.phpfreaks.com/topic/59968-solved-return-not-working/#findComment-298273 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.