Shibbir Ahmed
Shibbir Ahmed

Reputation: 95

Php undefine variable issue

Following is the function which provide random string... but i'm getting this error message Notice: Undefined variable: str in C:\xampp\htdocs\webrootfinal\forgotpasspr.php on line 5.........

function rand_string( $length ) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";  
$size = strlen( $chars );
for( $i = 0; $i < $length; $i++ ) {
$str.= $chars[ rand( 0, $size - 1 ) ];
}
return $str;                        
}
$my_string = rand_string( 10 );

Any Idea or Solution...

Upvotes: 0

Views: 427

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798716

Give $str a value before you start concatenating to it.

Upvotes: 2

Related Questions