有什么问题,无论我做什么打印都一样?一个帮助将不胜感激。
<?php
if(isset($_POST['submit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$connection = mysqli_connect('localhost', 'root', '', 'ayaneshapp');
if($connection) {
echo "Logged in!";
} else {
die("Sorry! Something went wrong.");
}
$query = "SELECT * FROM ayaneshtable ";
$result = mysqli_query($connection, "SELECT * FROM ayaneshtable");
if(!$result) {
die('404 ERROR');
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="col-sm-6">
<?php
while($row = mysqli_fetch_row($result)) {
echo $row['username'];
}
?>
</div>
</div>
</body>
</html>
答案 0 :(得分:0)
$result
为空,因为您的代码未放入if语句中。每次在未设置$_POST['submit']
的情况下访问页面时,都会引发此错误。
因此,要解决此问题,您既必须将while循环包装在相同的if语句中,也要确保$result
被填充,而不管$_POST['submit']
中是否有东西。