【发布时间】:2020-06-21 02:08:39
【问题描述】:
这是代码有什么问题,它不能正常工作 注意::没有错误显示或重定向到 print.php
$conn=mysqli_connect("localhost","root","","degree");
$sql="select * from students where regno=$regno";
$res= mysqli_query($conn,$sql);
if(mysqli_num_rows($res) >0)
{
echo "<script>alert('Student Already Exists')</script)" ;
}
else{
$query="INSERT into students (id,name,regno,program,fname,stcnic,phone,mobile,email,address,gender,gown,relname1,
relation1,relcnic1,relname2,relation2,relcnic2,gust1,guestrel1,guestcnic1,guest2,guestrel2,guestcnic2)
values('','$name',$regno,'$program','$fname','$stcnic',$phone,$mobile,'$email','$address','$gender','$gown','$relname1',
'$relation1','$relcnic1','$relname2','$relation2','$relcnic2','$guest1','$guestrel1','$guestcnic1','$guest2','$guestrel2','$guestcnic2')";
$result=mysqli_query($conn,$query);
if($result)
{
$_SESSION['id']=$regno;
header("location:print.php");
}
}
【问题讨论】:
-
$phone,$mobile周围没有引号。也许这些不仅仅是数字? -
您的查询未准备好(SQL 注入已获批准。),值为“”的第二个 id 不正确,您必须在 mysql 表自动增量中设置 ID,并且不要在查询中设置。
-
如果在此会话检查时插入另一个会话会怎样?
-
它工作正常,但是(警告不使用 javascript)——简单的 echo“用户已经存在”;正在工作,我想显示警报消息。
标签: php mysql validation insert