craig
craig

Reputation: 31

Generating random words in PHP

This is my code, but I am getting an error called "Undefined function get_random_word". Help.

if(isset($_POST['submit'])){

    $email = mysqli_real_escape_string($connect,trim($_POST['email']));


        $new_password = get_random_word(6, 13);
        if($new_passowrd==false){
            throw new Exception('Oops! ');
        }

        $rand_number = rand(0,999);
        $new_password .= $rand_number;
        mysqli_select_db($connect,"membership");
        $result = "update users set password = sha1('".$new_password."')
        where email = '".$email."'";
        $q = mysqli_query($connect,$result) or die(mysqli_error($connect));
        if(!q){
            throw new Exception('Oops!');
        }
        else
        {
            return $new_password;
        }
    }


?>

Can someone help me create it. I want to generate a random password for the user. Thanks

Upvotes: 0

Views: 525

Answers (5)

MrWhite
MrWhite

Reputation: 45829

As mentioned, get_random_word() is not a standard PHP function.

Somebody else with the same problem, and how to proceed.

And once you've solved the above, you have a typo that will prevent your code from proceeding...

if($new_passowrd==false){
  throw new Exception('Oops! ');
}

Upvotes: 1

jd.
jd.

Reputation: 4098

get_random_word is not a standard php function. Apparently, get_random_word() is in the user_auth_fns.php5 library.

http://www.phpbuilder.com/board/archive/index.php/t-10331068.html

Upvotes: 2

Pradeep Singh
Pradeep Singh

Reputation: 3634

You declared the function

$new_password = get_random_word(6, 13);

but not defined the function

Upvotes: 0

Jonah
Jonah

Reputation: 10091

That error tells you that get_random_word() has not been declared. You either need to find out where it went, or create it. get_random_word() is not a built-in function.

Upvotes: 0

Skilldrick
Skilldrick

Reputation: 70849

You need to define a function called get_random_word. You can't call a function you haven't defined.

Upvotes: 1

Related Questions