您好我正在尝试将数据插入到具有相同指令的两个表中,但仍未正确将数据转到表一而不是表二
这是我的代码
$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 我在这里做错了什么
答案 0 :(得分:1)
$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 :(得分:0)
mysqli_multi_query 执行一个或多个以分号连接的查询。
$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 );