Yousef Altaf
Yousef Altaf

Reputation: 2763

try to insert data into two tables with the same instructions not working

Hi I am trying to insert data into two tables with the same instructions but still not getting it right the data goes to table one and not table two

this is my code

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

the data go to project_info_arabic and not project_info what I did wrong here

Upvotes: 0

Views: 60

Answers (2)

Awlad Liton
Awlad Liton

Reputation: 9351

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

Notice
You did not concated your query with semicolon( http://www.php.net/manual/en/mysqli.multi-query.php ) so you have assigned twice in $putData. It is overwrite your previous query and hold the latest query. So Its only inserted data in second table not in the first table.

Upvotes: 1

sumit
sumit

Reputation: 15464

mysqli_multi_query Executes one or multiple queries which are concatenated by a semicolon.

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

Upvotes: 0

Related Questions