[英]In .php file, when add php code to html, html not works
在.php文件中,當將php代碼添加到html時,只有php代碼之外的html才起作用,但是在php代碼中,html則不起作用。 但是,當我刪除php代碼塊時,html再次起作用,並將表單顯示為html。
請任何建議為什么會這樣...
我的代碼在這里:
<div class="container" style="margin: 2em 5em";>
<h3>Update Category</h3><hr/>
<form action="http://localhost/twlp/mvc_two/Category/insertCategory" method="post">
<?php
if(isset($catById)){
foreach($catById as $value){
?>
<div class="form-group">
<label for="text">Category Name:</label>
<input type="text" class="form-control" name="name" required="1" value="<?php echo $value['name']; ?>"/>
</div>
<div class="form-group">
<label for="text">Category Title:</label>
<input type="text" class="form-control" name="title" required="1" value="<?php echo $value['title']; ?>"/>
</div>
<button type="submit" name="submit" class="btn btn-default">Update</button>
<?php } } ?>
</form>
</div>
問題出在$ catById。
我定義了一個示例$ catById。 然后頁面運行良好。
<?php
$value1=array('name'=>'test 1-name','title'=>'test 1-title');
$value2=array('name'=>'test 2-name','title'=>'test 2-title');
$catById=array($value1,$value2);
?>
<div class="container" style="margin: 2em 5em";>
<h3>Update Category</h3><hr/>
<form action="http://localhost/twlp/mvc_two/Category/insertCategory" method="post">
<?php
if(isset($catById)){
foreach($catById as $value){
?>
<div class="form-group">
<label for="text">Category Name:</label>
<input type="text" class="form-control" name="name" required="1" value="<?php echo $value['name']; ?>"/>
</div>
<div class="form-group">
<label for="text">Category Title:</label>
<input type="text" class="form-control" name="title" required="1" value="<?php echo $value['title']; ?>"/>
</div>
<button type="submit" name="submit" class="btn btn-default">Update</button>
<?php
}
} ?>
</form>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.