嗨,我正在尝试用相同的指令将数据插入两个表中,但仍然没有正确,数据被放到表一而不是表二。
这是我的密码
$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,我在这里做错了什么
发布于 2014-01-07 17:02:56
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 );发布于 2014-01-07 17:05:10
$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中分配了两次。它将覆盖您以前的查询并保存最新的查询。所以它只将数据插入到第二个表中,而不是在第一个表中。
https://stackoverflow.com/questions/20977444
复制相似问题