genzedu777 Posted October 10, 2010 Share Posted October 10, 2010 Hi guys, I am just wondering if there is a proper method to streamline my codes, whenever I perform multiple INSERTs into tables? Probably like INNER JOIN method etc? Thanks $query = "INSERT INTO practice_user (name, email, password, dob, category, comments) VALUES ('$name', '$email', '$password', '$dob', '$category', '$comments')"; $result = mysqli_query($dbc, $query) or die(mysql_error()); $query2 = "INSERT INTO location (name) VALUES ('$location')"; $result = mysqli_query($dbc, $query2) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/215524-any-proper-methods-for-multiple-insert-command/ Share on other sites More sharing options...
BlueSkyIS Posted October 10, 2010 Share Posted October 10, 2010 just a note that you probably don't want to mix mysqli and mysql functions. I notice you query with mysqli_query(), but then you die with error mysql_error(). Quote Link to comment https://forums.phpfreaks.com/topic/215524-any-proper-methods-for-multiple-insert-command/#findComment-1120710 Share on other sites More sharing options...
genzedu777 Posted October 10, 2010 Author Share Posted October 10, 2010 Thanks, it was a mistake. Hi, do u have any suggestions of how I could streamline the INSERTs codes? Quote Link to comment https://forums.phpfreaks.com/topic/215524-any-proper-methods-for-multiple-insert-command/#findComment-1120736 Share on other sites More sharing options...
chintansshah Posted October 10, 2010 Share Posted October 10, 2010 It is not possible with two different tables. for single table you can do that $query = "INSERT INTO practice_user (name, email, password, dob, category, comments) VALUES ('$name', '$email', '$password', '$dob', '$category', '$comments'), ('$name', '$email', '$password', '$dob', '$category', '$comments'), ('$name', '$email', '$password', '$dob', '$category', '$comments'), ('$name', '$email', '$password', '$dob', '$category', '$comments'), ('$name', '$email', '$password', '$dob', '$category', '$comments')"; $result = mysqli_query($dbc, $query) Quote Link to comment https://forums.phpfreaks.com/topic/215524-any-proper-methods-for-multiple-insert-command/#findComment-1120750 Share on other sites More sharing options...
genzedu777 Posted October 10, 2010 Author Share Posted October 10, 2010 Thanks for the clarifications Quote Link to comment https://forums.phpfreaks.com/topic/215524-any-proper-methods-for-multiple-insert-command/#findComment-1120767 Share on other sites More sharing options...
mikosiko Posted October 10, 2010 Share Posted October 10, 2010 as you are using mysqli you could consider implement your multiples Insert with mysqli_multi_query examples here: http://php.net/manual/en/mysqli.multi-query.php Quote Link to comment https://forums.phpfreaks.com/topic/215524-any-proper-methods-for-multiple-insert-command/#findComment-1120789 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.