查询解决方案

我在启动项目时遇到查询问题。它说


解析错误:语法错误,C:\Users\ahmed\Documents\zadacaveb\Call Center\Dateof_seminars\forma.php第 34 行中出现意外的“$sql”(T_VARIABLE)


当我按下按钮 Dodaj (engl.添加)。我没有看到我的查询有问题,所以如果你看到我的查询中哪里有错误,请告诉我。我将展示我的forma代码.php这是一个问题,以及来自文件索引.php和删除.php的代码。这两个文档工作正常,但问题是形式上的.php


索引.php


<?php


require('../util/session.php');

require('../util/db.php');

require('../Frontend/header.php');

require('../Frontend/footer.php');


if(!isset($_SESSION['user'])) {

    header('Location: /Call Center/Login/index.php');

}


$stmt = $db->query('SELECT * FROM dateof_seminars');

$rows = $stmt->fetchAll();


echo $header;


?>



<br/>

<br/>


<div class="container">

    <a href="/Call Center/Dateof_seminars/forma.php" class="btn btn-primary mt-3 mb-3 float-left">Dodaj</a>

    <br/>

    <br/>

    <table class="table">

      <thead>

        <tr>

          <th scope="col">#</th>

          <th scope="col">Počinje datuma</th>

          <th scope="col">Završava datumom</th>

          <th scope="col">Instruktor ID</th>

          <th scope="col">Seminar ID</th>

          <th scope="col">Klijent ID</th>

        </tr>

      </thead>

      <tbody>

        <?php foreach($rows as $row) { ?>

      <tr>

          <th scope="row"><?php echo $row['id']; ?></th>

          <td><?php echo $row['date_from']; ?></td>

          <td><?php echo $row['date_to']; ?></td>

          <td><?php echo $row['instructor_id']; ?></td>

          <td><?php echo $row['seminars_id']; ?></td>

          <td><?php echo $row['clients_id']; ?></td>

          <td>


          <a class="btn btn-primary" href="/Call Center/Dateof_seminars/forma.php?id=<?php echo $row['id']; ?>">Edit</a>


          <a class="btn btn-danger" href="/Call Center/Dateof_seminars/delete.php?id=<?php echo $row['id']; ?>">Delete</a>


        </tr>

        <?php } ?>

      </tbody>

    </table>

    </center>

</div>


<?php

echo $footer;

?> 

函数式编程
浏览 92回答 2
2回答

开心每一天1111

您在一行上缺少一个分号,即:$dateFrom = $_POST['date_from'];$dateTo = $_POST['date_to'];$instructorId = $_POST['instructor_id'];$seminarsId = $_POST['seminars_id'];$clientsId = $_POST['clients_id']&nbsp; <----$sql = 'INSERT INTO dateof_seminars (date_from, date_to, instructor_id, seminars_id, clients_id) VALUES (:date_from, :date_to, :instructor_id, :seminars_id, :clients_id)';$stmt = $db->prepare($sql);因此,下一行是出乎意料的,编译器不知道该如何处理它。$sql

杨魅力

在提到的第34行(这个:$sql = 'INSERT INTO dateof_seminars (date_from, date_to, instructor_id, seminars_id, clients_id) VALUES (:date_from, :date_to, :instructor_id, :seminars_id, :clients_id)';&nbsp;)你必须用双引号替换单引号,就像这样$sql = "INSERT INTO dateof_seminars (date_from, date_to, instructor_id, seminars_id, clients_id) VALUES (:date_from, :date_to, :instructor_id, :seminars_id, :clients_id)";据我所知,你不能在单引号中使用变量。
打开App,查看更多内容
随时随地看视频慕课网APP