ekalath Posted July 19, 2005 Share Posted July 19, 2005 I couldn't find a way to insert multiple records in a database through a single page. What i want is to make a suitable form to fill the data in and with a submit button to insert all the records to the database. Now i can do two records at a time with phpMyadmin application, but only two records at a time. If i want more what can i do Quote Link to comment https://forums.phpfreaks.com/topic/2407-insert-into-mysql-table/ Share on other sites More sharing options...
neylitalo Posted July 20, 2005 Share Posted July 20, 2005 All you would really do to insert more than one record is just build more than one query, and run all of them. Example: [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--][span style=\"color:#0000BB\"]<?php $name [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"Bob Jones\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$phone [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"123-4567\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$email [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"bob@email.com\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$query1 [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"INSERT INTO people(\"[/span][span style=\"color:#0000BB\"]name[/span][span style=\"color:#DD0000\"]\", \"[/span][span style=\"color:#0000BB\"]phone[/span][span style=\"color:#DD0000\"]\", \"[/span][span style=\"color:#0000BB\"]email[/span][span style=\"color:#DD0000\"]\") VALUES(\\"[/span][span style=\"color:#0000BB\"]$name[/span][span style=\"color:#007700\"]&[/span][span style=\"color:#FF8000\"]#092;\", \\"$phone\\", \\"$email\\")\"; [/span][span style=\"color:#0000BB\"]mysql_query[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$query1[/span][span style=\"color:#007700\"]); [/span][span style=\"color:#0000BB\"]$name [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"John Smith\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$phone [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"555-7890\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$email [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"john@email.com\"[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$query2 [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"INSERT INTO people(\"[/span][span style=\"color:#0000BB\"]name[/span][span style=\"color:#DD0000\"]\", \"[/span][span style=\"color:#0000BB\"]phone[/span][span style=\"color:#DD0000\"]\", \"[/span][span style=\"color:#0000BB\"]email[/span][span style=\"color:#DD0000\"]\") VALUES(\\"[/span][span style=\"color:#0000BB\"]$name[/span][span style=\"color:#007700\"]&[/span][span style=\"color:#FF8000\"]#092;\", \\"$phone\\", \\"$email\\")\"; [/span][span style=\"color:#0000BB\"]mysql_query[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$query[/span][span style=\"color:#007700\"]); [/span][span style=\"color:#0000BB\"]?>[/span] [/span][!--PHP-Foot--][/div][!--PHP-EFoot--] This adds those two entries to the database... just keep going, assembling queries (or however you do it), and running them with mysql_query(); Quote Link to comment https://forums.phpfreaks.com/topic/2407-insert-into-mysql-table/#findComment-7944 Share on other sites More sharing options...
dbdummy Posted August 27, 2005 Share Posted August 27, 2005 a simpler way might be [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]$insertsql = \"INSERT INTO `people` (`name`, `phone`, `email`) VALUES (\'john doe\', \'555.555.5555\', \'john@john.com\'), (\'joe doe\', \'555.555.5551\', \'joe@john.com\'), (\'jane doe\', \'555.555.5552\', \'jane@john.com\'), (\'jill doe\', \'555.555.5553\', \'jill@john.com\')\"; mysql_query($insertsql, $conn); [/span][!--PHP-Foot--][/div][!--PHP-EFoot--] Quote Link to comment https://forums.phpfreaks.com/topic/2407-insert-into-mysql-table/#findComment-8191 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.