<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Iterator &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/iterator/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>One Form &#8211; Multiple DB Records</title>
		<link>/2010/06/04/one-form-multiple-db-records/</link>
		<comments>/2010/06/04/one-form-multiple-db-records/#respond</comments>
		<pubDate>Fri, 04 Jun 2010 12:05:08 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Control flow]]></category>
		<category><![CDATA[elegant solution]]></category>
		<category><![CDATA[Foreach]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[Iterator]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[web form]]></category>

		<guid isPermaLink="false">/?p=1584</guid>
		<description><![CDATA[I&#8217;ve the impression that even it&#8217;s a simple technique it remains quite misunderstood! What&#8217;s the Goal? You&#8217;ve a simple HTML form with several groups of form elements. Imagine the situation with title and link groups. You can have 1, 2 or more title/link pairs which you&#8217;d like to save in a database table, where perhaps &#8230; <a href="/2010/06/04/one-form-multiple-db-records/" class="more-link">Continue reading <span class="screen-reader-text">One Form &#8211; Multiple DB Records</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/04/09/secure-forms-with-zend-framework/" rel="bookmark" title="Secure Forms with Zend Framework">Secure Forms with Zend Framework </a></li>
<li><a href="/2010/04/20/how-to-sanitize-user-input-in-php/" rel="bookmark" title="How to Sanitize User Input in PHP?">How to Sanitize User Input in PHP? </a></li>
<li><a href="/2010/09/10/automatically-upload-images-with-php-directly-from-the-uri/" rel="bookmark" title="Automatically Upload Images with PHP Directly from the URI">Automatically Upload Images with PHP Directly from the URI </a></li>
<li><a href="/2010/11/03/how-to-overcome-zend_cache_frontend_pages-problem-with-cookies/" rel="bookmark" title="How to Overcome Zend_Cache_Frontend_Page&#8217;s Problem with Cookies">How to Overcome Zend_Cache_Frontend_Page&#8217;s Problem with Cookies </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve the impression that even it&#8217;s a simple technique it remains quite misunderstood!</p>
<h2>What&#8217;s the Goal?</h2>
<p>You&#8217;ve a simple HTML form with several groups of form elements. Imagine the situation with title and link groups. You can have 1, 2 or more title/link pairs which you&#8217;d like to save in a database table, where perhaps there are only three columns &#8211; id, title, link.</p>
<h2>What is the Shortest Path to the Solution?</h2>
<p>In fact the task can be done by many ways, but there&#8217;s one really elegant solution. As it appears in many occasions PHP and HTML are born to work together!</p>
<h3>1. First Step</h3>
<p>Create your web form by simply modifying a bit the element names. Usually when you have an input you simply name it after the database column or something similar.</p>
<pre lang="html4strict">
<form method="POST">
	<input type="text" name="db_column_name" />
</form>
</pre>
<p>In reality PHP and HTML allows the name to be an array element, just like so:</p>
<pre lang="html4strict">
<form method="POST">
	<input type="text" name="link[0][title]" />
	<input type="text" name="link[0][url]" />
	
	<input type="text" name="link[1][title]" />
	<input type="text" name="link[1][url]" />
</form>
</pre>
<h3>2. Second Step</h3>
<p>Than all this comes in the _POST array in PHP, but formatted in an array manner, so you can simply foreach it!</p>
<pre lang="php">
<?php

foreach ($_POST['link'] as $link) {
	insert_into_db($link['title'], $link['url']);
}

?>
</pre>
<p>That is simply enough!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/04/09/secure-forms-with-zend-framework/" rel="bookmark" title="Secure Forms with Zend Framework">Secure Forms with Zend Framework </a></li>
<li><a href="/2010/04/20/how-to-sanitize-user-input-in-php/" rel="bookmark" title="How to Sanitize User Input in PHP?">How to Sanitize User Input in PHP? </a></li>
<li><a href="/2010/09/10/automatically-upload-images-with-php-directly-from-the-uri/" rel="bookmark" title="Automatically Upload Images with PHP Directly from the URI">Automatically Upload Images with PHP Directly from the URI </a></li>
<li><a href="/2010/11/03/how-to-overcome-zend_cache_frontend_pages-problem-with-cookies/" rel="bookmark" title="How to Overcome Zend_Cache_Frontend_Page&#8217;s Problem with Cookies">How to Overcome Zend_Cache_Frontend_Page&#8217;s Problem with Cookies </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/06/04/one-form-multiple-db-records/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
