else语句与phpmyadmin中的数据库存储运行时间相似

时间:2018-03-30 07:17:44

标签: php mysql

我想检查输入数据是否存储在数据库中。此代码有效但仅当数据有效但数据无效时,其他语句的运行次数与数据库中的列数一样多。

<?php 
include_once('connection.php');
if(isset($_POST['Submit'])){
$username= $_POST['user'];
$password= $_POST['pass'];
$query = "SELECT * FROM form1 ";
$result = mysqli_query($conn,$query);
if ( false===$result ) {
printf("error: %s\n", mysqli_error($conn));
}
else {
 //echo 'done.';
}
while ($row = mysqli_fetch_assoc($result))
{
$name = $row['username'];
$code = $row['password'];
if((($username == $name) && ($username!="" )) && (($password == $code) && 
($password!="")) )
{
echo "valid";
header("Location:practice.php");
}
else{
echo "please enter correct username <br/>";
}
}
}
?>

输出

please enter correct username 
please enter correct username 
please enter correct username 
please enter correct username 
please enter correct username 
please enter correct username 
please enter correct username 
please enter correct username 
please enter correct username 
please enter correct username 
please enter correct username 
please enter correct username 
please enter correct username 
please enter correct username 
please enter correct username 
please enter correct username 
please enter correct username 
please enter correct username

}

#18数据库值存储在我的数据库中,并显示此消息18次 我不明白这段代码的问题是什么

0 个答案:

没有答案