Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6857577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:02:27+00:00 2026-05-27T02:02:27+00:00

Error reporting Notice: Undefined variable: random_chars in wamp\www\php_sandbox\idgen.php on line 21 Call Stack: #

  • 0

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;
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:02:27+00:00Added an answer on May 27, 2026 at 2:02 am

    You have to declare and initialize $random_chars before you start concatenating stuff to it.

    Fixed below. I set random_chars to a null string. $random_chars = "";

    $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;}
    }
    
    $random_chars = ""; //Here
    
    foreach($keys as $key){
          $random_chars .= $characters[$key];
    }
    $randNum = rand(2327,9987); $randLet = rand(2327,9987);
    echo $random_chars . $randNum;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With error reporting on, or even for best practice, when unsetting a variable in
I am writing a custom error handling / reporting function for PHP file upload
I've turned on all error reporting to clean up some undefined indexes, just to
I'am allways developing php stuff with error reporting and notices actived. But now i
Does python have some undefined variable / debug mode which will output a notice/warning?
What would be the best way to implement a simple crash / error reporting
When a script runs under Apache, I insert $_SERVER['SERVER_NAME'] value into an error reporting
It seems not good for me, reporting errors like 'General Error: '+...., Is there
Since i changed my error reporting level to error_reporting(E_ALL | E_STRICT); I am facing
I've been happily using the error suppression operator on my PHP dev setup. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.