PHP reporting error. DB verify how to?
Posted
by
iamfab
on Stack Overflow
See other posts from Stack Overflow
or by iamfab
Published on 2011-11-18T17:45:08Z
Indexed on
2011/11/18
17:51 UTC
Read the original article
Hit count: 179
Error reporting Notice:
Undefined variable: random_chars in wamp\www\php_sandbox\idgen.php on line 21
Call Stack:
# Time Memory Function Location
1 0.0045 678928 {main}( ) ..\idgen.php:0
GPB7446
How do I fix this error?
Using this code like an automatic unique id generator. How do I connect to DB to verify code is truly unique before allowing it to be assigned to a user creating a new account?
Thanks
<?php
$characters = array(
"A","B","E","F","G","H","J","K","M","N","P","R","S","T","W","X","Y","Z");
$keys = array();
while(count($keys) < 3) {
$x = mt_rand(0, count($characters)-1);
if(!in_array($x, $keys)) {
$keys[] = $x;
}
}
foreach($keys as $key){
$random_chars .= $characters[$key];}
$randNum = rand(2327,9987); $randLet = rand(2327,9987);
echo $random_chars . $randNum;
?>
© Stack Overflow or respective owner