database - how to insert multiple records in php -



database - how to insert multiple records in php -

i have problem while inserting multiple record in db

html

<input type="input" name="row[][name]"> <input type="input" name="row[][surname]"> <input type="input" name="row[][name]"> <input type="input" name="row[][surname]">

php

$returneddata = $_post['row']; $sql = array(); foreach( $returneddata $row ) { $sql[] = '("'.mysql_real_escape_string($row['name']).'", '.mysql_real_escape_string($row['surname']).')'; } mysql_query('insert tablename (name, surname) values '.implode(',', $sql));

but error opens 4 rows while mean opens new row each input.

how can insert 2 records ?

new info

when write posted values usingforeach can see values properly, thing couldnt find solution insert in table

foreach($returneddata $data) { echo '<pre>'; echo $data['name']; echo $data['surname']; }

to insert row each instance of post should be:

foreach( $returneddata $row ) { $sql[] = '("'.mysql_real_escape_string($row['name']).'", '.mysql_real_escape_string($row['surname']).')'; mysql_query('insert tablename (name, surname) values '.implode(',', $sql)); }

cause way inserts lastly one.

i think trying achieve

php database

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -