为什么while循环冷时HTML代码与php结合不执行?

时间:2020-08-03 01:49:56

标签: php html forms

我正在使用while将PHP代码与HTML代码结合起来进行CRUD操作。我希望HTML代码在每次执行while()之后重复执行。但是它给出了错误:“解析错误:语法错误,第21行的C:\ xampp \ htdocs \ php \ index1.php中出现意外的'?>'”。 任何人都可以解决此问题。我已经提到了以下代码:

       <?php
$con=mysqli_connect("localhost","root","","student");

$sql="select * from student_php";

$res=mysqli_query($con,$sql);

?>
<table>

   <tr>
      <td>S.No</td>
      <td>Name</td>
      <td>City</td>
   
   </tr>
<?php 
 while($row =mysqli_fetch_assoc($res){ 
 ?>
   <tr>
      <td>S.No</td>
      <td><?php echo $row['name']?></td>
      <td><?php echo $row['city']?></td>
   
   </tr>
  <?php } 
?>
</table>

1 个答案:

答案 0 :(得分:-3)

您的while循环未关闭。

while($row =mysqli_fetch_assoc($res)

需要成为

while($row =mysqli_fetch_assoc($res))