Hi all i am wondering how do insert multiple rows into a mysql table for example i have 5 fields of email text filed and user fields and i want to post the values of them into a table but not sure exactly how this is what i have
Well first you need to establish a connection to the database. Once you have accomplished that you use the following if you connection object is a pdo instance. Furthermore, you shouldn’t place POST or REQUEST variables directly into sql before running some type of validation on them. This is less of a concern when binding, but you should still at least check the input against a basic pattern or number of characters.
the best way to insert multiple rows into a table is not with a loop, because that produces multiple INSERT statements, which are executed sequentially –
INSERT INTO users (username,email) VALUES ( ‘curly’, ‘woowoo’ );
INSERT INTO users (username,email) VALUES ( ‘larry’, ‘heymoe’ );
INSERT INTO users (username,email) VALUES ( ‘moe’, ‘whyioughta’ );
INSERT INTO users (username,email) VALUES ( ‘shemp’, ‘eebeebeeb’ );
INSERT INTO users (username,email) VALUES ( ‘joe’, ‘ohyou’ );
INSERT INTO users (username,email) VALUES ( ‘curlyjoe’, ‘geethanks’ );
instead, the best way is to make only one call to the database –
This is the error i got from the code you gave me above
Notice: Undefined variable: records in C:\Program Files\xampp\htdocs\wikclanscriptsv2\ est.php on line 33
Warning: Invalid argument supplied for foreach() in C:\Program Files\xampp\htdocs\wikclanscriptsv2\ est.php on line 33
Notice: Undefined variable: insert in C:\Program Files\xampp\htdocs\wikclanscriptsv2\ est.php on line 43
INSERT INTO members (username,password,email,rank,recruiter,disabled) VALUES ;