简体   繁体   中英

In .php file, when add php code to html, html not works

In .php file, when add php code to html, only the html that out of php code works, but within the php code the html not works. But when I delete the php code blocks, the html works again and shows the form as the html.

Please any suggestion why this happening...

My codes are here:

<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>

The problem is from $catById.

I defined an example $catById. Then the page runs well.

<?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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM