我正在尝试在PHP页面上显示MySQL表。表头正确显示,但没有出现MySQL表行,并且出现MySQL表行数据时也会出现错误。我在运行PHP页面时收到此错误:
警告:mysqli_fetch_row()要求参数1为mysqli_result,第61行/home/www/s.com/yogaclub/index.php中给出布尔值
这是我页面的代码:
<?php
$username = "d";
$password = "dar";
$hostname = "localhost";
//connection to the database
$con = mysqli_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
if ($con) { } else { echo "didn't work";}
?>
<!doctype html>
<head>
<style>
body {
font-family:verdana;
}
#box {
background-color:yellow;
position:relative;
color:red;
padding-top:10px;
margin:auto;
width:600px;
border-radius:15px
padding-bottom:10px;
}
.container {
width: 500px;
clear: both;
}
.container input {
width: 100%;
clear: both;
}
#pic {
align:left
}
</style>
<title>Yoga Club</title>
</head>
<body bgcolor="blue">
<div id="box">
<h3><center>Yoga Club!</center></h3>
<img src="thOX7T2TIR.jpg" id="pic"><span style="text-align:center; align:right"><span style="color:blue;"></span>
<?php
$result = mysqli_query($con, "SELECT * FROM yogaclub");
echo "<table border='1'>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>";
while($row = mysqli_fetch_row($result))
{
echo "<tr>";
echo "<td>" . $row['fname'] . "</td>";
echo "<td>" . $row['lname'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?><br /><br /><center>Please Sign up to the Adventures of Yoga.
We will be doing lots of different kinds of stretches.</center>
<?php /* if(isset($_POST['add']))
{
$sql = mysql_query("insert into yogaclub(fname, lname) values('$_GET['fname']', '$_GET['lname']')");
} else { echo "nonsend"; } */
?><br /><form method="post" action="<?php $_PHP_SELF ?>">First Name: <input name="fname" type="text"><Br />Last Name: <input type="text"><br />Address: <input type="text"><br />Email: <input type="text"><br />Phone Number: <input type="text"><input type="hidden" value="send" name="send"><br />Yoga Experience: <select>
<option value="none">None</option>
<option value="alittle">A little</option>
<option value="alot">A lot</option>
</select> <br />Age: <input type="text" size="3"><br /><br />
<input type="submit" name="add" value="Sign me up!"></form></span>
</div>
</body>
</html>
非常感谢所有帮助。
答案 0 :(得分:0)
测试$ result以验证查询至少返回一行可能是一个好主意。
答案 1 :(得分:0)
而不是
while($row = mysqli_fetch_row($result))
请尝试使用
进行测试while($row= mysqli_fetch_assoc($result))