Reply to Re: Looping INSERT from checkbox info

Your name:

Reply:


Posted by Bob Stearns on 10/13/60 11:42

Aaron Reimann wrote:
> I am trying to insert info if a checkbox is selected. The checkboxes
> are created from this code (pulled from mysql):
>
> ##########
> $ministry_info_query = "SELECT * FROM ministries WHERE inactive = 0
> ORDER BY title"; // selecting all ministries that are active
>
> $ministry_info_results = mysql_query($ministry_info_query, $mysql_link)
> or die("Bad query: ".mysql_error());
>
> // if the results are 0, the print this
> if (mysql_num_rows($ministry_info_results) == "0") {
> print "<br><strong>No ministries are in the
> database.</strong>";
>
> } else {
>
> print "<table cellpadding=\"5\">\n";
>
> while ($row = mysql_fetch_array($ministry_info_results)) {
> print "<tr>\n";
> echo "\t<td>$row[title]</td>\n";
> echo "\t<td><input name=\"comments[]\"
> type=\"checkbox\"
> value=\"$row[id]\"></td>\n";
> print "</tr>\n";
> // ending the loop (while)
> }
>
> print "</table>\n";
>
> }
>
> mysql_free_result($ministry_info_results);
> ##########
>
> Once the form is submitted, I need the ones that are checked to insert
> the info into the "comments" table....i am kind of new at this...this
> is kind of what I am thinking the code needs to look like:
>
> $sql = "INSERT INTO comments ($row[people_id], id_ministries) VALUES(";
>
> for($i=0;$i<count($comments);$i++) {
> // DON'T KNOW WHAT TO DO
>
> }
>
> Does that make sense?
>
> thank you for any advise.
>
A little ddl would help here. What if the person already has a comment?
Does the new one replace the old one?

What does $row[reople_id] give you in the INSERT statement? At that
point the parens are supposed to contain column names from the table
comments.

[Back to original 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

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