首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >尝试将数据插入两个具有相同指令不工作的表中。

尝试将数据插入两个具有相同指令不工作的表中。
EN

Stack Overflow用户
提问于 2014-01-07 16:57:41
回答 2查看 59关注 0票数 0

嗨,我正在尝试用相同的指令将数据插入两个表中,但仍然没有正确,数据被放到表一而不是表二。

这是我的密码

代码语言:javascript
复制
$putData = "INSERT INTO project_info       (id, pro_title, pro_address, pro_area_from, pro_area_to, pro_kind, pro_description, pro_finish, pro_big_rooms, pro_small_rooms, pro_reception, pro_big_bathroom, pro_small_bathroom, propActivity, yb, map) values ( '', '$pro_name', '$pro_address', '$area_from', '$area_to', '$pro_kind', '$pro_description', '$pro_finish', '$pro_big_rooms', '$pro_small_rooms', '$pro_receptions', '$pro_big_bathrooms', '$pro_small_bathrooms', '$proActivity', '$pro_yb', '$googleMap')";    
$putData = "INSERT INTO project_info_arabic(id, pro_title, pro_address, pro_area_from, pro_area_to, pro_kind, pro_description, pro_finish, pro_big_rooms, pro_small_rooms, pro_reception, pro_big_bathroom, pro_small_bathroom, propActivity, yb, map) values ( '', '$pro_name', '$pro_address', '$area_from', '$area_to', '$pro_kind', '$pro_description', '$pro_finish', '$pro_big_rooms', '$pro_small_rooms', '$pro_receptions', '$pro_big_bathrooms', '$pro_small_bathrooms', '$proActivity', '$pro_yb', '$googleMap')";
$result = mysqli_multi_query($db, $putData)or die( $db->error );

数据转到project_info_arabic,而不是project_info,我在这里做错了什么

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-01-07 17:02:56

mysqli_multi_query执行由分号连接的一个或多个查询。

代码语言:javascript
复制
$putData="INSERT INTO project_info(id, pro_title, pro_address, pro_area_from, pro_area_to, pro_kind, pro_description, pro_finish, pro_big_rooms, pro_small_rooms, pro_reception, pro_big_bathroom, pro_small_bathroom, propActivity, yb, map) values ( '', '$pro_name', '$pro_address', '$area_from', '$area_to', '$pro_kind', '$pro_description', '$pro_finish', '$pro_big_rooms', '$pro_small_rooms', '$pro_receptions', '$pro_big_bathrooms', '$pro_small_bathrooms', '$proActivity', '$pro_yb', '$googleMap')";
//i have concatenated query with semicolon
$putData.=";"."INSERT INTO project_info_arabic(id, pro_title, pro_address, pro_area_from, pro_area_to, pro_kind, pro_description, pro_finish, pro_big_rooms, pro_small_rooms, pro_reception, pro_big_bathroom, pro_small_bathroom, propActivity, yb, map) values ( '', '$pro_name', '$pro_address', '$area_from', '$area_to', '$pro_kind', '$pro_description', '$pro_finish', '$pro_big_rooms', '$pro_small_rooms', '$pro_receptions', '$pro_big_bathrooms', '$pro_small_bathrooms', '$proActivity', '$pro_yb', '$googleMap')";

 $result=mysqli_multi_query($db, $putData)or die( $db->error );
票数 0
EN

Stack Overflow用户

发布于 2014-01-07 17:05:10

代码语言:javascript
复制
$putData = "INSERT INTO project_info       (id, pro_title, pro_address, pro_area_from, pro_area_to, pro_kind, pro_description, pro_finish, pro_big_rooms, pro_small_rooms, pro_reception, pro_big_bathroom, pro_small_bathroom, propActivity, yb, map) values ( '', '$pro_name', '$pro_address', '$area_from', '$area_to', '$pro_kind', '$pro_description', '$pro_finish', '$pro_big_rooms', '$pro_small_rooms', '$pro_receptions', '$pro_big_bathrooms', '$pro_small_bathrooms', '$proActivity', '$pro_yb', '$googleMap');";    
$putData .= "INSERT INTO project_info_arabic(id, pro_title, pro_address, pro_area_from, pro_area_to, pro_kind, pro_description, pro_finish, pro_big_rooms, pro_small_rooms, pro_reception, pro_big_bathroom, pro_small_bathroom, propActivity, yb, map) values ( '', '$pro_name', '$pro_address', '$area_from', '$area_to', '$pro_kind', '$pro_description', '$pro_finish', '$pro_big_rooms', '$pro_small_rooms', '$pro_receptions', '$pro_big_bathrooms', '$pro_small_bathrooms', '$proActivity', '$pro_yb', '$googleMap')";
$result = mysqli_multi_query($db, $putData)or die( $db->error );

通知

您没有将查询与分号( http://www.php.net/manual/en/mysqli.multi-query.php )连接起来,因此您在$putData中分配了两次。它将覆盖您以前的查询并保存最新的查询。所以它只将数据插入到第二个表中,而不是在第一个表中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20977444

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档