我需要防止表单数据的重复数据输入。 功能是:表单包含部分和学生数量。我们可以添加多个部分。我需要防止重复的部分名称。 请查看代码,
$connect = mysqli_connect("localhost","root","mysql","inventory");
$number = count($_REQUEST["name"]);
if($number > 0)
{
for($i=0; $i<$number; $i++)
{
if(trim($_REQUEST["name"][$i]) != '')
{
$id = $_REQUEST['idref'];
$c = $_REQUEST["clas"];
$s = $_REQUEST["name"][$i];
$k = $_REQUEST["k"][$i];
$query = mysqli_query($connect, "SELECT * FROM budget WHERE section='".$s."'");
if(mysqli_num_rows($query) > 0)
{
echo "already exists";
}
else
{
$sql = "INSERT INTO budget(sid,k,section,stu) VALUES('$id','$c','$k','$s')";
mysqli_query($connect, $sql);
}
}
}
}
else
{echo "Enter section";
}