sayedsohail Posted October 22, 2007 Share Posted October 22, 2007 Hi everyone, I am just wondering how to insert values in two tables at same time. Here is single insert code, which works perfectly fine. I am just wondering to insert into two tables and ignoring if values are exists. i.e, insert ignore, not sure how to achieve this in mysql 5.0. $q1 = "insert into fmodels (member_id, make_id, model, model_date, description) VALUES ('$memid', '$fm', '$fmod','$today', '$fdes')"; $result= mysql_query($q1); Any help is highly appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/74321-insert-ignore-into-two-tables-mysql-50-php/ Share on other sites More sharing options...
only one Posted October 22, 2007 Share Posted October 22, 2007 Just run two mysql queries. mysql_query("INSERT INTO `fmodels` (`member_id`, `make_id`, `model`, `model_date`, `description`) VALUES ('$memid', '$fm', '$fmod','$today', '$fdes')"); mysql_query("INSERT INTO `table2` (`member_id`, `make_id`, `model`, `model_date`, `description`) VALUES ('$memid', '$fm', '$fmod','$today', '$fdes')"); Quote Link to comment https://forums.phpfreaks.com/topic/74321-insert-ignore-into-two-tables-mysql-50-php/#findComment-375493 Share on other sites More sharing options...
sasa Posted October 22, 2007 Share Posted October 22, 2007 or mysql_query("INSERT INTO `fmodels` (`member_id`, `make_id`, `model`, `model_date`, `description`) VALUES ('$memid', '$fm', '$fmod','$today', '$fdes'); INSERT INTO `table2` (`member_id`, `make_id`, `model`, `model_date`, `description`) VALUES ('$memid', '$fm', '$fmod','$today', '$fdes')"); Quote Link to comment https://forums.phpfreaks.com/topic/74321-insert-ignore-into-two-tables-mysql-50-php/#findComment-375616 Share on other sites More sharing options...
sayedsohail Posted October 22, 2007 Author Share Posted October 22, 2007 Can someone helps how to achieve, insert ignore, not sure how to achieve this in mysql 5.0. Quote Link to comment https://forums.phpfreaks.com/topic/74321-insert-ignore-into-two-tables-mysql-50-php/#findComment-375839 Share on other sites More sharing options...
dbo Posted October 22, 2007 Share Posted October 22, 2007 What does insert ignore mean? Quote Link to comment https://forums.phpfreaks.com/topic/74321-insert-ignore-into-two-tables-mysql-50-php/#findComment-375842 Share on other sites More sharing options...
sayedsohail Posted October 23, 2007 Author Share Posted October 23, 2007 it means ignore inserting a record, if records already exists with same details. Quote Link to comment https://forums.phpfreaks.com/topic/74321-insert-ignore-into-two-tables-mysql-50-php/#findComment-375869 Share on other sites More sharing options...
dbo Posted October 23, 2007 Share Posted October 23, 2007 So it sounds like you'll need to write a trigger in mysql. Quote Link to comment https://forums.phpfreaks.com/topic/74321-insert-ignore-into-two-tables-mysql-50-php/#findComment-375893 Share on other sites More sharing options...
teng84 Posted October 23, 2007 Share Posted October 23, 2007 it means ignore inserting a record, if records already exists with same details. this is sql not php but try REPLACE INTO Quote Link to comment https://forums.phpfreaks.com/topic/74321-insert-ignore-into-two-tables-mysql-50-php/#findComment-375897 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.