为了账号安全,请及时绑定邮箱和手机立即绑定

查询解决方案

查询解决方案

PHP
函数式编程 2022-08-19 15:40:42
我在启动项目时遇到查询问题。它说解析错误:语法错误,C:\Users\ahmed\Documents\zadacaveb\Call Center\Dateof_seminars\forma.php第 34 行中出现意外的“$sql”(T_VARIABLE)当我按下按钮 Dodaj (engl.添加)。我没有看到我的查询有问题,所以如果你看到我的查询中哪里有错误,请告诉我。我将展示我的forma代码.php这是一个问题,以及来自文件索引.php和删除.php的代码。这两个文档工作正常,但问题是形式上的.php索引.php<?phprequire('../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><?phpecho $footer;?> 
查看完整描述

2 回答

?
开心每一天1111

TA贡献1836条经验 获得超13个赞

您在一行上缺少一个分号,即:


$dateFrom = $_POST['date_from'];

$dateTo = $_POST['date_to'];

$instructorId = $_POST['instructor_id'];

$seminarsId = $_POST['seminars_id'];

$clientsId = $_POST['clients_id']  <----


$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


查看完整回答
反对 回复 2022-08-19
?
杨魅力

TA贡献1811条经验 获得超5个赞

在提到的第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)'; )

你必须用双引号替换单引号,就像这样

$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)";

据我所知,你不能在单引号中使用变量。


查看完整回答
反对 回复 2022-08-19
  • 2 回答
  • 0 关注
  • 91 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信