<?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>Team Tutorials &#187; dhtml</title>
	<atom:link href="http://teamtutorials.com/tag/dhtml/feed" rel="self" type="application/rss+xml" />
	<link>http://teamtutorials.com</link>
	<description></description>
	<lastBuildDate>Tue, 27 Dec 2011 18:58:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Receiving Dynamic Textbox Data</title>
		<link>http://teamtutorials.com/other-tutorials/receiving-dynamic-textbox-data?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=receiving-dynamic-textbox-data</link>
		<comments>http://teamtutorials.com/other-tutorials/receiving-dynamic-textbox-data#comments</comments>
		<pubDate>Mon, 30 Jun 2008 05:01:57 +0000</pubDate>
		<dc:creator>Mike Maguire</dc:creator>
				<category><![CDATA[HTML Tutorials]]></category>
		<category><![CDATA[Other Tutorials]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[dhtml]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://teamtutorials.com/?p=1590</guid>
		<description><![CDATA[In this tutorial we will be working with PHP and MySQL to insert the data that was inserted into the text boxes on the <a href="http://teamtutorials.com/web-development-tutorials/dynamically-add-textbox-to-site">Dynamically Add Textbox to Site tutorial</a>. We will collect the data and insert the values into a database]]></description>
			<content:encoded><![CDATA[<div style="float: right;">
 <script type="text/javascript"> 
 <!-- 
 microsoft_adunitid="2178"; 
 microsoft_adunit_width="180"; 
 microsoft_adunit_height="150";  
 microsoft_adunit_legacy="false";//--> 
 </script><br />
 <script type="text/javascript" src="http://adsyndication.msn.com/delivery/getads.js" ></script>
</div>
<p>n this tutorial we will be working with PHP and MySQL to insert the data that was inserted into the text boxes on the <a href="http://teamtutorials.com/web-development-tutorials/dynamically-add-textbox-to-site">Dynamically Add Textbox to Site tutorial</a>. We will collect the data and insert the values into a database. To start we need to make sure our file that we are using the make this data is called insert.php (as we named it in the last tutorial.) This file will be called when you click the “Add Invoice” button. </p>
<pre class="brush: php; title: Code Snippet:; notranslate">
&lt;?php

$conn = mysql_connect (&quot;localhost&quot;,&quot;username&quot;,&quot;password&quot;) or die
('cannot connect to database error: '.mysql_error());
mysql_select_db ('test');
</pre>
<p>This starts the php and makes the connection to the database so that we can insert the values.  </p>
<pre class="brush: php; title: Code Snippet:; notranslate">
$quantity = $_POST['quantity'];
$desc = $_POST['desc'];
$itemno = $_POST['itemno'];
$ourcost = $_POST['ourcost'];
$cost = $_POST['cost'];
$distid = $_POST['distid'];
$invoice = $_POST['invoice'];
$integer = 0;
</pre>
<p>This declares all of our POST variables (the names of the textboxes in the form from the last page). Notice the additioni variable that we called integer. We are going to use this to go through all the results. This sets each php variable equal to the array of values we set on the last page. We can set which variable we are trying to use by defining the number of the array we would like to grab. For example:</p>
<p>$quantity[0] – Quantity of first item.<br />
$quantity[1] – Quantity of second item.<br />
Ect….</p>
<pre class="brush: php; title: Code Snippet:; notranslate">
while (count($quantity)&gt;$integer) {
if (($distid[$integer] &lt;&gt; &quot;&quot;) &amp;&amp; ($desc[$integer] &lt;&gt; &quot;&quot;) &amp;&amp; ($quantity[$integer] &lt;&gt; &quot;&quot;)&amp;&amp; ($cost[$integer] &lt;&gt; &quot;&quot;) &amp;&amp; ($itemno[$integer] &lt;&gt; &quot;&quot;) &amp;&amp; ($ourcost[$integer] &lt;&gt; &quot;&quot;)){
$sql =  &quot;INSERT INTO `test`.`item` (`InvoiceNo`, `DistID`, `ItemDesc`, `ItemQuantity`, `ItemCost`, `ItemNo`, `OurCost`)
	VALUES ('&quot;.$invoice.&quot;', '&quot;.$distid[$integer].&quot;', '&quot;.$desc[$integer].&quot;', '&quot;.$quantity[$integer].&quot;', '&quot;.$cost[$integer].&quot;', '&quot;.$itemno[$integer].&quot;', '&quot;.$ourcost[$integer].&quot;')&quot;;
mysql_query($sql);
</pre>
<p>This section of code looks worse than it actually is. The function it is doing is actually relatively simple. The first line means that the system will do every thing after it until the amount of values in the array $quantity is greater than the value we set ($integer). The count function simply counts the number of values in an array. So if we insert 2 items this section will run until the value of $integer passes the count of $quantity. The second line checks all the variables for values and runs the insert query if none are blank. Notice that we are inserting $integer instead of a number so that this number can be incremented every time it is run. So on the first pass of the code:</p>
<p>$quantity[$integer] = $quantity[0]</p>
<pre class="brush: php; title: Code Snippet:; notranslate">
echo &quot;$quantity[$integer] $desc[$integer](s) bought from Distribution Center $distid[$integer]
have/has been added to the database with an Item Number of $itemno[$integer]
and a customer cost of $cost[$integer] and a company cost of $ourcost[$integer]&lt;br /&gt;&quot;;
</pre>
<p>This line simply echoes the values of all the variables into a sentence so we can see it was inserted into the database. </p>
<pre class="brush: php; title: Code Snippet:; notranslate">
}
else{
echo &quot;Item number &quot;.($integer+1).&quot; is missing values and cannot be inserted.&quot;;
}
</pre>
<p>The first bracket end the if statement. Everything up until that point would have been run if the statement were true. The next line starts the else statement. This will be run if one of the fields on the last page was blank. It will echo the statement above. Notice that we echoes the value of integer plus one since the integer starts on 0 instead of 1.</p>
<pre class="brush: php; title: Code Snippet:; notranslate">
$integer = ($integer + 1);
}
?&gt;
</pre>
<p>Finally we increment our variable and then end the while statement. Once the variable is incremented it will try the while statement again. If it passes, the section of code will be run again but this time the value of our integer will be higher by one number. Finally we end our PHP.</p>
<p>This concludes writing the receiving file. </p>
<p><a href='http://teamtutorials.com/wp-content/uploads/2008/06/dynamic-data-retrieval_01.jpg'><img src="http://teamtutorials.com/wp-content/uploads/2008/06/dynamic-data-retrieval_01-699x407.jpg" alt="dynamic-data-retrieval_01" title="dynamic-data-retrieval_01" width="699" height="407" class="alignnone size-medium wp-image-1591" /></a></p>
<p>Let’s open our original file and insert two items with the above information. Notice the blank item number.</p>
<p><a href='http://teamtutorials.com/wp-content/uploads/2008/06/dynamic-data-retrieval_02.jpg'><img src="http://teamtutorials.com/wp-content/uploads/2008/06/dynamic-data-retrieval_02-699x407.jpg" alt="dynamic-data-retrieval_02" title="dynamic-data-retrieval_02" width="699" height="407" class="alignnone size-medium wp-image-1592" /></a></p>
<p>Your screen should look like this if you did it exactly the way I did. This means that the first item we inserted was successfully put into the database, but the second one was not since there was no item number. </p>
<p>This concludes this tutorial. I hope it is helpful and you were able to follow it. Thanks for reading.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://teamtutorials.com/web-development-tutorials/dynamically-add-textbox-to-site" title="Dynamically Add Textbox to Site">Dynamically Add Textbox to Site</a></li><li><a href="http://teamtutorials.com/web-development-tutorials/hide-and-show-a-div-using-javascript" title="Hide and Show a Div Using Javascript">Hide and Show a Div Using Javascript</a></li><li><a href="http://teamtutorials.com/web-development-tutorials/using-jquery-to-reorder-a-list-and-update-a-database" title="Using jQuery to Reorder a List and Update a Database">Using jQuery to Reorder a List and Update a Database</a></li><li><a href="http://teamtutorials.com/web-development-tutorials/html-tutorials/javascript-progress-bar" title="JavaScript Progress Bar">JavaScript Progress Bar</a></li><li><a href="http://teamtutorials.com/web-development-tutorials/styling-html-tables-with-tablecloth" title="Styling HTML Tables with TableCloth">Styling HTML Tables with TableCloth</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://teamtutorials.com/other-tutorials/receiving-dynamic-textbox-data/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

