You are here: Re: insert multiple records into one table (one form) « PHP Programming Language « IT news, forums, messages
Re: insert multiple records into one table (one form)

Posted by NC on 04/15/06 07:41

GJPeacock@gmail.com wrote:
>
> Maybe i should re-phrase my question. I'm using php with a MySQL
> database, and i would like to know how to insert a new record into a
> table for each checked item on one form.

OK, let's say you have a form:

<form method="POST" action="insert.php">
<input type="checkbox" name="id[]" value="32">Article #32<br>
<input type="checkbox" name="id[]" value="38">Article #38<br>
<input type="checkbox" name="id[]" value="45">Article #45<br>
<input type="checkbox" name="id[]" value="59">Article #59<br>
<input type="Submit">
</form>

Now, let's assume the user checked articles #32 and #59. These values
will be available to insert.php as fields in $_POST['id'], which in
this case will be an array. So in insert.php you can write:

$query = 'INSERT INTO related_articles (id) VALUES (' .
implode('), (', $_POST['id']) . ')';
$result = mysql_query($query)
or die('Could not execute INSERT query');

That's it, really...

Cheers,
NC

 

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

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