1 回答

TA贡献1790条经验 获得超9个赞
您应该在循环内生成代码。
//list of possible characters in generated code
$charmap = "QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm";
//note using `:randomcode` instead of the direct variable
$stmt = $pdo->prepare("insert into AGEGroup (AGE) values (:age, :randomcode)");
foreach ($_POST['age'] as $age) {
//create a "random" string that is 8 characters.
//string will never repeat any characters, and can create duplicates
$code = 'NT' . substr(str_shuffle($charmap), -8);
//send variables to query on each loop
$stmt->execute([':age' => $age, ':randomcode' => $code]);
}
正如我在代码注释中所说,这种方法可能有创建重复代码的倾向。它也不包含任何重复的字母/数字。
- 1 回答
- 0 关注
- 152 浏览
添加回答
举报