skip to Main Content

helper.php

<?php

 function h()
{
    $randomchar = str_shuffle('abcdefghjklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ234567890!$%^&!$%^&');
            $password = substr($randomchar, 0, 12);
            $generated_pass = $password;
}

view

        <input type="text" id="lname" name="pass" value="<?php echo $generated_pass;?>"><br><br>

error ErrorException
PHP 8.1.12
9.48.0
Undefined variable $generated_pass

tried to do it like above but got error.

2

Answers


  1. functions should return its local value:

    function h()
    {
        $randomchar = str_shuffle('abcdefghjklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ234567890!$%^&!$%^&');
        return substr($randomchar, 0, 12);
    }
    

    then you should call function:

    <input type="text" id="lname" name="pass" value="<?php echo h();?>"><br><br>
    
    Login or Signup to reply.
  2. I think you need to call the function instead.
    <input type="text" id="lname" name="pass" value="<?php echo h(); ?>"><br><br>

    Also make sure that the helper.php file is loaded.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search