0

这是我的php代码,有什么问题吗?

惠普代码:

<?php  

include '../includes/config.php';

//SQL QUERY
$query = mysqli_query($conn, "SELECT * FROM post ORDER BY id ASC");

if (isset($_POST["submit"])) {
    $title = $_POST["title"];
    $description = $_POST["description"];
    $article = $_POST["article"];
}

?>
//HTML
<?php if (isset($_POST["update"])) { ?>
<body>
    <form method="post">
      <div class="form-group">
        <label for="exampleFormControlFile1">Choose the image</label>
        <input type="file" class="form-control-file" id="exampleFormControlFile1">
      </div>
      <div class="form-group">
        <label">Title</label>
        <input type="text" class="form-control" name="title" placeholder="Title" <?php echo $row["title"]; ?>>
      </div>
      <div class="form-group">
        <label for="exampleInputPassword1">Description</label>
        <input type="text" class="form-control" name="description" placeholder="Description">
      </div>
      <div class="form-group">
        <label for="exampleFormControlTextarea1">Article</label>
        <textarea class="form-control" name="article" rows="3"></textarea>
      </div>
      <button type="submit" class="btn btn-primary" name="submit">Post</button>
    </form>
    <?php if (mysqli_num_rows($query)) { ?>
        <?php while ($row = mysqli_fetch_array($query)) {?>
            <strong>
                <h1><?php echo $row["title"]; ?></h1>
            </strong>
            <h3><?php echo $row["description"]; ?></h3>
            <p><?php echo $row["article"]; ?></p>
            <button class="btn btn-warning" name="update">
                <a href="#">Update</a>
            </button>
            <hr />
        <?php } ?>
    <?php } ?>
</body>

解析错误:语法错误,第 51 行 C:\xampp\htdocs\my-blog\admin\includes\content\edit_article.php 中的文件意外结束。

任何人都可以帮助我吗?谢谢回答

4

3 回答 3

0
<?php 
include '../includes/config.php';

//SQL QUERY
$query = mysqli_query($conn, "SELECT * FROM post ORDER BY id ASC");

if (isset($_POST["submit"])) {
    $title = $_POST["title"];
    $description = $_POST["description"];
    $article = $_POST["article"];
}

if (isset($_POST["update"])) { ?>
<body>
    <form method="post">
        <div class="form-group">
            <label for="exampleFormControlFile1">Choose the image</label>
            <input type="file" class="form-control-file" id="exampleFormControlFile1">
        </div>
        <div class="form-group">
            <label>Title</label>
            <input type="text" class="form-control" name="title" placeholder="Title" <?php echo $row["title"]; ?>>
        </div>
        <div class="form-group">
            <label for="exampleInputPassword1">Description</label>
            <input type="text" class="form-control" name="description" placeholder="Description">
        </div>
        <div class="form-group">
            <label for="exampleFormControlTextarea1">Article</label>
            <textarea class="form-control" name="article" rows="3"></textarea>
        </div>
        <button type="submit" class="btn btn-primary" name="submit">Post</button>
    </form>
    <?php if (mysqli_num_rows($query)) { ?>
    <?php while ($row = mysqli_fetch_array($query)) {?>
    <strong>
        <h1><?php echo $row["title"]; ?></h1>
    </strong>
    <h3><?php echo $row["description"]; ?></h3>
    <p><?php echo $row["article"]; ?></p>
    <button class="btn btn-warning" name="update">
        <a href="#">Update</a>
    </button>
    <hr />
    <?php } ?>
    <?php } ?>
</body>

<?php } ?>
于 2018-03-21T05:48:31.290 回答
0

问题就在这里

<?php while ($row = mysqli_fetch_array($query)) {?>

之后只给一个空格{

<?php while ($row = mysqli_fetch_array($query)) { ?>
于 2018-03-21T05:52:46.047 回答
0

这是因为您在文件中缺少一个 }。$_POST['update'] 没有右括号。所以在最后添加一个右括号

于 2018-03-21T06:36:21.910 回答