php - 尝试进行两个 sql 查询,但总是出错

标签 php mysql

$query=mysqli_query($conn,"INSERT INTO bus_info(bus_id,route_num,school_name) values('$BusNum','$RouteNum','$SchoolName'); INSERT INTO bus_loc(bus_id,lat,lon) values ((SELECT bus_id from bus_info where bus_info.bus_id='$BusNum'),'$latitude','$longitude')"); 

PHP

$BusNum = $_POST["BusNum"];
$SchoolName = $_POST["SchoolName"];
$RouteNum = $_POST["RouteNum"];
$latitude = $_POST["lat"];
$longitude = $_POST["lng"];

数据库已连接,即返回 true。在此处输入代码

失败: 发送数据时出错:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near INSERT INTO bus_loc(bus_id,lat,lon) values ((SELECT bus_id from bus_info where b at line 1

最佳答案

发件人:http://php.net/manual/de/mysqli.query.php#87203

mysqli::query() can only execute one SQL statement.

Use mysqli::multi_query() when you want to run multiple SQL statements within one query.

如何使用 mysqli_multi_query:http://php.net/manual/de/mysqli.multi-query.php

关于php - 尝试进行两个 sql 查询,但总是出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32945387/

相关文章:

php 在 csv 中写入希伯来语/UTF-8

php - 连续显示3张图片的问题

php - Symfony2 表单为什么我的表单返回警告 : json_encode(): recursion detected?

php - mysql不会返回正确的结果

mysql - 按组计算行的绝对差之和

mysql - 可以对损坏的查询执行 SQL 注入(inject)吗?

php - twitter rss 或以其他方式获取 100 条最新推文

php - 为什么 TCP 工作,而 UDP 不工作?

mysql - Dropwizard Liquibase,运行 db migrate.xml 文件,该文件位于 jar 内

python - 安装 MySQLdb(用于 python)作为非压缩蛋