我试图在php循环中嵌套HTML代码。它给出了该块的错误。 “解析错误:语法错误,第119行的C:\ xampp \ htdocs \ cms \ admin \ categories.php中的文件意外结束”
<form action="categories.php" method="post">
<div class="form-group">
<label for="cat-title">Update</label>
<?php //EDIT & UPDATE //
if (isset($_GET['edit'])){
$edit_row_title = $_GET['edit'];
$query = "SELECT * FROM category WHERE cat_id = {$edit_row_title}";
$edit_query = mysqli_query($connect,$query);
while($row = mysqli_fetch_assoc($edit_query)){
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
?>
<input class="form-control" name="cat_title" type="text" value="<?php if(isset($cat_title)){echo $cat_title;} ?>">
<?php } ?> }
<input type="text" name="cat-title" class="form-control" >
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" name="submit" value="Edit Category" >
</div>
</form>
但是当我在html代码之前放置大括号时,它可以工作。期待while循环无法正常工作。
<form action="categories.php" method="post">
<div class="form-group">
<label for="cat-title">Update</label>
<?php //EDIT & UPDATE //
if (isset($_GET['edit'])){
$edit_row_title = $_GET['edit'];
$query = "SELECT * FROM category WHERE cat_id = {$edit_row_title}";
$edit_query = mysqli_query($connect,$query);
while($row = mysqli_fetch_assoc($edit_query)){
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
} ?>
<input class="form-control" name="cat_title" type="text" value="<?php if(isset($cat_title)){echo $cat_title;} ?>">
<?php } ?>
<input type="text" name="cat-title" class="form-control" >
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" name="submit" value="Edit Category" >
</div>
</form>
答案 0 :(得分:0)
更改
<?php } ?> }
要
<?php } }?>
更新代码
<form action="categories.php" method="post">
<div class="form-group">
<label for="cat-title">Update</label>
<?php //EDIT & UPDATE //
if (isset($_GET['edit'])){
$edit_row_title = $_GET['edit'];
$query = "SELECT * FROM category WHERE cat_id = {$edit_row_title}";
$edit_query = mysqli_query($connect,$query);
while($row = mysqli_fetch_assoc($edit_query)){
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
?>
<input class="form-control" name="cat_title" type="text" value="<?php if(isset($cat_title)){echo $cat_title;} ?>">
<?php } }?> //Changes
<input type="text" name="cat-title" class="form-control" >
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" name="submit" value="Edit Category" >
</div>
</form>
答案 1 :(得分:0)
while($row = mysqli_fetch_assoc($edit_query)){
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
?>
<input class="form-control" name="cat_title" type="text" value="<?php if(isset($cat_title)){echo $cat_title;} ?>">
<?php } ?> }
在最后一行中,在结束PHP标记之后添加一个结束花括号。
我假设它关闭if
,但PHP不会解释它。因此,在文件的末尾,PHP仍然期望该块被关闭,从而导致解析错误。
答案 2 :(得分:0)
请更新以下代码
$mutes = GameMute::where('expires_at ', '>', new DateTime('today'))->orderBy('created_at', 'asc')->get();
答案 3 :(得分:0)
您必须将<?php } ?> }
更改为<?php } }?>
,您的问题才能解决。
以下是根据您给定的代码段更新的代码:
<form action="categories.php" method="post">
<div class="form-group">
<label for="cat-title">Update</label>
<?php //EDIT & UPDATE //
if (isset($_GET['edit'])){
$edit_row_title = $_GET['edit'];
$query = "SELECT * FROM category WHERE cat_id = {$edit_row_title}";
$edit_query = mysqli_query($connect,$query);
while($row = mysqli_fetch_assoc($edit_query)){
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
?>
<input class="form-control" name="cat_title" type="text" value="<?php if(isset($cat_title)){echo $cat_title;} ?>">
<?php } }?> //Changes => This changes requred on your code.
<input type="text" name="cat-title" class="form-control" >
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" name="submit" value="Edit Category" >
</div>
</form>