I am trying to output randomly generated values via "echo" command and write them to a database. The "echo" output is no problem, but in the mySQL table only the first digit of the generated number is given. In theory there should be displayed five digits. https://i.stack.imgur.com/1KPGi.png
if ($submitbutton){
$length = 5;
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz@#$&*";
$size = strlen( $chars );
echo "Key: ";
for( $i = 0; $i < $length; $i++ ) {
$str= $chars[ rand( 0, $size - 1 ) ];
echo $str;
$sql = "INSERT INTO regkey (regkey) VALUES (?)";
$stmt = mysqli_prepare($link, $sql);
$str1 = $str;
mysqli_stmt_bind_param($stmt, "s", $str1);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
mysqli_close($link);
}
If I try to enter another predefined value via php, this works without problems.