1
我只是想从我所做的学生的所有查询结果中随机输入密码。在我的情况下,我试图产生,但它只返回1个生成的密码给所有查询的学生(约45名学生)。我应该如何做一个随机的。 PLSS帮助.. 继承人我的代码如何生成随机密码
<?php
if(isset($_POST['generate'])){
$charset = '[email protected]#$%^&*()_+';
$generated_pass = substr(str_shuffle($charset), 0, 12);
$generate = $_POST['generate'];
}
?>
<form method="post" action='enroll_student.php' name ='register'>
<?php
$yr = date("Y");
if ($result = $mysqli->query("SELECT
tbl_studentreg.studId,
tbl_studentreg.fname,
tbl_studentreg.lname,
tbl_studentreg.mname,
tbl_studentreg.dob,
tbl_studentreg.address,
tbl_department.departmentName,
tbl_studentreg.sy
FROM tbl_studentreg
Inner Join tbl_department ON tbl_studentreg.departmentId = tbl_department.departmentId WHERE tbl_studentreg.sy = '$yr' "))
{
if ($result->num_rows > 0)
{
echo "<table width= '1000'>";
echo "<tr><th>StudentID</th><th>Name</th><th>Date of Birth</th><th>Address</th><th>Department</th><th>School Year</th><th>Password</th></tr>";
while ($row = $result->fetch_object())
{
echo "<tr>";
echo "<td align='center'>" . $row->studId . "</td>";
echo "<td align='center'>" . $row->fname . " ". $row->mname ." ". $row->lname ." </td>";
echo "<td align='center'>".$row->dob."</td>";
echo "<td align='center'>" . $row->address. "</td>";
echo "<td align='center'>".$row->departmentName."</td>";
echo "<td align='center'>".$row->sy."</td>";
if(isset($generated_pass)) {
//how could i make this one generate random password for every students..?
for($i=0; $i <= $row->studId; $i++){
echo "<td>$generated_pass</td>";
}
}
echo "</tr>";
}
echo "</table>";
}
else
{
echo "No Results.";
}
}
else
{
echo "Error: " . $mysqli->error;
}
$mysqli->close();
echo '<br>';
include 'count.php'; //this one will give the total no. of results, just ignore.
?>
<br />
<tr><td></td></tr><tr><td><input type='submit' name='generate' value='Generate'/></td></tr>
</table>
</form>
参考[this](http://stackoverflow.com/questions/1837432/how-to-generate-random-password-with-php?rq=1)和[this](http://stackoverflow.com/questions/6101956/generate-a-random-password-in-php?rq = 1)。 – 2013-02-19 06:22:18
您需要使密码生成器成为一个函数,并为您需要的每个新密码调用它。您只是一次创建它并反复使用同一个。 – Danny 2013-02-19 06:23:51
你的密码只产生一次 – fefe 2013-02-19 06:26:44