-3

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.

unknown
  • 7
  • 3
  • 1
    ... start giving your time to docs and learn how does a function work and how to return data from a fn. – OMi Shah Jan 22 '23 at 06:48

1 Answers1

3

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>
Iłya Bursov
  • 23,342
  • 4
  • 33
  • 57