0

This is my php code, is there something wrong?

HP CODE:

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

Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\my-blog\admin\includes\content\edit_article.php on line 51.

Anyone Can Help Me ? Thanks for Answering

Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69

3 Answers3

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 } ?>
vikalp
  • 330
  • 2
  • 9
  • Questions that are about basic PHP syntax errors should not be answered. They should be closed as a duplicate of [PHP Parse/Syntax Errors; and How to solve them?](//stackoverflow.com/questions/18050071) only. See: [Should one advise on off topic questions?](//meta.stackoverflow.com/q/276572/1768232). Off-topic questions can be closed and deleted, which could nullify your contribution anyway. – John Conde Mar 21 '18 at 11:44
0

problem is here

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

just give one space after {

<?php while ($row = mysqli_fetch_array($query)) { ?>
Bala
  • 913
  • 9
  • 18
  • Questions that are about basic PHP syntax errors should not be answered. They should be closed as a duplicate of [PHP Parse/Syntax Errors; and How to solve them?](//stackoverflow.com/questions/18050071) only. See: [Should one advise on off topic questions?](//meta.stackoverflow.com/q/276572/1768232). Off-topic questions can be closed and deleted, which could nullify your contribution anyway. – John Conde Mar 21 '18 at 11:45
0

This is because ur missing a } in the file . There is no closing bracket for the $_POST['update'] . So add a closing bracket at the end

Killer
  • 47
  • 3
  • Questions that are about basic PHP syntax errors should not be answered. They should be closed as a duplicate of [PHP Parse/Syntax Errors; and How to solve them?](//stackoverflow.com/questions/18050071) only. See: [Should one advise on off topic questions?](//meta.stackoverflow.com/q/276572/1768232). Off-topic questions can be closed and deleted, which could nullify your contribution anyway. – John Conde Mar 21 '18 at 11:45