I am trying to display a MySQL Table on my PHP page. The Table headers appear correctly but none of the MySQL table rows are appearing, and an error is also appearing where the MySQL table row data should appear. I am getting this error when I run my PHP page:
Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in /home/www/s.com/yogaclub/index.php on line 61
This is the code to my page:
<?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>
All help is greatly appreciated.
Instead of
while($row = mysqli_fetch_row($result))
please try to test with
while($row= mysqli_fetch_assoc($result))
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다