Multi INSERT to MySQL database from a multi input form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ozz
Forum Commoner
Posts: 26
Joined: Wed Aug 21, 2002 11:47 pm

Multi INSERT to MySQL database from a multi input form

Post by Ozz »

I need to make a form like:

ID1 - TITLE1 {input=text}
ID2 - TITLE2 {input=text}
....
I'm gonna make changes some of the inputs not all of them.
And when I submit form, changed rows will be inserted to another table.
I think its an array and for loop thing but I couldnt figure out the code.
Can anyone help me?
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Multi INSERT to MySQL database from a multi input form

Post by kendall »

Dude,

Please be more self explanatory man

but i think

Code: Select all

// input fields of form
<input name="field[]" id="field[]" type="text"/>
<input name="field[]" id="field[]" type="text"/>
// the from processor
foreach ($_POST['field'] as $field){
 $field.= $field.','
}
// mysql 
$query = "INSERT VALUES($field)";
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Re: Multi INSERT to MySQL database from a multi input form

Post by foobar »

kendall wrote:

Code: Select all

// mysql 
$query = "INSERT VALUES($field)";
Don't use this on a public server. An array can be easily submitted from a different form with malicious SQL that can potentially kill your data.

<edit>
And yes, being specific about your problem helps.
Check out the manual over at php.net . It's a great resource. Also, download the MySQL manual from http://www.mysql.org , it's invaluable. All your commands are right there.
</edit>
Post Reply