You are here: Re: inserting multiple lines from one form « All PHP « IT news, forums, messages
Re: inserting multiple lines from one form

Posted by Tyrone Slothrop on 08/13/05 17:55

On Sat, 13 Aug 2005 15:08:15 +0100, Peter Wilson
<pwilson@sci-comm.clara.net> wrote:

>Hi
>
>I am trying to work out how I can use one button on a form to insert
>multiple lines in to a mysql table.
>
>The table is generated from a mysql table in the first place.
>
>in the past I have put a button on each line but would like to advance
>my understanding and do it all in one push.
>
>Once I have done this I will want to do the same thing up updating the
>table.
>
>can anyone help or point me at a good website that explains how to do
>this.
>
>Many thanks
>
>Peter
>Motto "A smile aday keeps the blues away"
>
>http://www.sci-comm.clara.net/

Peter:

OK, I'll take a stab at this. I assume that when you say "lines" that
you mean records in a table. Most likely, the easiest way is to have
the field names post as an array, so you end up with a
multi-dimensional array.

For example:
<form method="post" action="a_url.php">
<input type="hidden" name="id[]" value="1">
<input type="text" name="field[]" value="cogs">
<br>
<input type="hidden" name="id[]" value="2">
<input type="text" name="field[]" value="widgets">
<br>
<input type="submit" value="update">
</form>


Then, on the receiving end:
<?php
for ($i=0; $i<count($_POST['id']); $i++)
{
mysql_query ("UPDATE table SET field=\"{$_POST['field'][$i]}\" WHERE
id = '{$_POST['id'][$i]}'");
}
?>

That should work but (as a warning) I am still on my first cup of
caffeine of the morning.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация