我需要使用n个用户名和密码创建n个用户。
如果我提供输入5
,abc
。5个用户应的用户名和密码,例如创建abc1
,abc2
,abc3
,abc4
和abc5
。
如何通过提供mysql插入查询在for循环中执行此操作?
这是我的表格
create.php
Create User :
<br><br>
<form action="add_res.php" method="post">
Count : <input type = "text" name="count"><br>
Name : <input type = "text" name="val">
<input type = "submit">
</form>
和add_res.php
<?php
$count=$_POST['count'];
$val=$_POST['val'];
include ('config.php');
echo "<b>".$count." Users Created"."</b>"."<br>";
echo "<u>"."The Users' List is given below"."</u>";
for ($i=1; $i <=$count; $i++)
{
$select=mysql_query("insert into student (username, password) VALUES
('$con', '$con')");
}
?>
我没有实现适当的for循环和适当的插入查询的想法。我该如何实现?
通过以下格式使用for循环和插入查询,
<?php
$count=$_POST['count'];
$val=$_POST['val'];
include ('config.php');
echo "<b>".$count." Users Created"."</b>"."<br>";
echo "<u>"."The Users' List is given below"."</u>";
for ($i=1; $i <=$count; $i++)
{
echo "<br>";
echo $val.$i;
$con=$val.$i;
$select=mysql_query("insert into student (username, password) VALUES
('$con', '$con')");
}
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句