我想在MySQL數據庫中檢索信息並顯示它html table.when我試着用這個代碼我得到錯誤message.i不能解決that.i是新的php.help我。這裏是我的代碼php代碼從mysql數據庫檢索數據並顯示在html表中
<?php
session_start();
?>
<?php
$conn = mysqli_connect("localhost","root","","doctor");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (isset($_POST['button'])) {
$sql="select Mid,Mname,Mnic,amount,month,bank from payments ";
}
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Approvals</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<br>
<br>
<div class="table-responsive">
<table id="mytable" class="table table-bordred table-striped" border="1">
<thead style="background-color: sandybrown">
<th><input type="checkbox" id="checkall" /></th>
<th>Doctor ID</th>
<th>Doctor Name</th>
<th>Payment Type</th>
<th>Mobile Number</th>
<th>Email</th>
<th>Pay Date</th>
</thead>
<tbody>
<tr>
<td><input type="checkbox" class="checkthis" /></td>
<?php
while($row = mysqli_fetch_assoc($sql)): ?>
<td > <?php echo $row['Mid']; ?> </td >
<td > <?php echo $row['Mname']; ?></td >
<td > <?php echo $row['Mnic']; ?> </td >
<td > <?php echo $row['amount']; ?></td >
<td > <?php echo $row['month']; ?> </td >
<td ><?php echo $row['bank']; ?></td >
</tr >
<?php endwhile ?>
</tbody>
</table>
<div class="form-group " align="center">
<a style="box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);border: 2px solid #4CAF50;background-color: white;color: black;width: 15%; float: right" href="#" target="_blank" type="button" id="button" name="button" class="btn btn-primary btn-lg btn-block login-button">Submit</a>
</div>
</div>
</div>
</div>
</body>
</html>
未定義的變量:SQL在C:\瓦帕\ WWW \醫生\ approval.php線警告:mysqli_fetch_assoc()預計參數1是mysqli_result,null在C:\ wamp \ www \ Doctor \ approval.php中給出 –
@ s.ravi您是否嘗試過下面解答的解決方案? – user3284463
@ s.ravi檢查答案..並通過[mysqli](http://php.net/manual/en/book.mysqli.php) –