<?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>TangoRangers.com's Blog &#187; coding</title>
	<atom:link href="http://blog.tangorangers.com/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tangorangers.com</link>
	<description>Misc crap and such</description>
	<lastBuildDate>Fri, 30 Jul 2010 01:13:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Using Javascript to hide single/multiple div tags with the same name Part 2</title>
		<link>http://blog.tangorangers.com/2009/08/using-javascript-to-hide-singlemultiple-div-tags-with-the-same-name-part-2/</link>
		<comments>http://blog.tangorangers.com/2009/08/using-javascript-to-hide-singlemultiple-div-tags-with-the-same-name-part-2/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 23:36:19 +0000</pubDate>
		<dc:creator>DaijoubuKun</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.tangorangers.com/?p=194</guid>
		<description><![CDATA[Recently I was asked by a comment from my previous post Using Javascript to hide single/multiple div tags with the same name on how to get multiple buttons to control multiple div tags. For example, 2 div classes need to be hidden or shown with 2 different buttons controlling them. Turns out this is fairly [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was asked by a comment from my previous post <a href="http://blog.tangorangers.com/2009/03/using-javascript-to-hide-singlemultiple-div-tags-with-the-same-name/">Using Javascript to hide single/multiple div tags with the same name</a> on how to get multiple buttons to control multiple div tags. For example, 2 div classes need to be hidden or shown with 2 different buttons controlling them. Turns out this is fairly simple. Basically you can use some previous code and alter some variable names in the javascript, but to make things simple here is the code.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> getElementsByClass<span style="color: #009900;">&#40;</span>searchClass<span style="color: #339933;">,</span> domNode<span style="color: #339933;">,</span> tagName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>domNode <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> domNode <span style="color: #339933;">=</span> document<span style="color: #339933;">;</span>
     <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>tagName <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> tagName <span style="color: #339933;">=</span> <span style="color: #3366CC;">'*'</span><span style="color: #339933;">;</span>
     <span style="color: #003366; font-weight: bold;">var</span> el <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #003366; font-weight: bold;">var</span> tags <span style="color: #339933;">=</span> domNode.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span>tagName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #003366; font-weight: bold;">var</span> tcl <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot; &quot;</span><span style="color: #339933;">+</span>searchClass<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot; &quot;</span><span style="color: #339933;">;</span>
     <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>j<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>tags.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #003366; font-weight: bold;">var</span> test <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot; &quot;</span> <span style="color: #339933;">+</span> tags<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">className</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; &quot;</span><span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>test.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span>tcl<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>
               el<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> tags<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
     <span style="color: #000066; font-weight: bold;">return</span> el<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> hidden <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">function</span> toggle_hideme1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     hidden <span style="color: #339933;">=</span> <span style="color: #339933;">!</span>hidden<span style="color: #339933;">;</span>
     <span style="color: #003366; font-weight: bold;">var</span> newDisplay<span style="color: #339933;">;</span>
     <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>hidden<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          newDisplay <span style="color: #339933;">=</span> <span style="color: #3366CC;">'block'</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #000066; font-weight: bold;">else</span>
     <span style="color: #009900;">&#123;</span>
          newDisplay <span style="color: #339933;">=</span> <span style="color: #3366CC;">'none'</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #003366; font-weight: bold;">var</span> showfirst <span style="color: #339933;">=</span> getElementsByClass<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div_class_name&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;div&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> showfirst.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          showfirst<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span> <span style="color: #339933;">=</span> newDisplay<span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> hiddenb <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">function</span> toggle_hideme2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     hiddenb <span style="color: #339933;">=</span> <span style="color: #339933;">!</span>hiddenb<span style="color: #339933;">;</span>
     <span style="color: #003366; font-weight: bold;">var</span> newDisplay<span style="color: #339933;">;</span>
     <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>hiddenb<span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
          newDisplay <span style="color: #339933;">=</span> <span style="color: #3366CC;">'block'</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #000066; font-weight: bold;">else</span>
     <span style="color: #009900;">&#123;</span>
          newDisplay <span style="color: #339933;">=</span> <span style="color: #3366CC;">'none'</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #003366; font-weight: bold;">var</span> showsecond <span style="color: #339933;">=</span> getElementsByClass<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div_class_name&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;div&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> k <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> k <span style="color: #339933;">&lt;</span> showsecond.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> k<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          showsecond<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span> <span style="color: #339933;">=</span> newDisplay<span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>For the variables &#8216;showfirst&#8217; and &#8216;showsecond&#8217; you can call them what ever you want, just make sure they stay the same in only one function, not two. Be sure to change &#8216;div_class_name&#8217; to a custom name for each field.</p>
<p>Also, these are setup to be hidden first, you can change that by swapping the &#8216;newDisplay = &#8216; lines.</p>
<p>For the HTML code we are going to use check boxes. We need two boxes each with names that call the function.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;input type=&quot;checkbox&quot; name=&quot;showone&quot; id=&quot;showone&quot; value=&quot;showone&quot; onClick=&quot;toggle_hideme1('showone');&quot;&gt;&lt;br /&gt;
&lt;input type=&quot;checkbox&quot; name=&quot;showtwo&quot; id=&quot;showtwo&quot; value=&quot;showtwo&quot; onClick=&quot;toggle_hideme2('showtwo');&quot;&gt;&lt;br /&gt;</pre></div></div>

<p>If you want the boxes checked to start first swap the &#8216;newDisplay =&#8217; lines, and use this.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;input type=&quot;checkbox&quot; name=&quot;showone&quot; id=&quot;showone&quot; value=&quot;showone&quot; onClick=&quot;toggle_hideme1('showone');&quot; CHECKED&gt;&lt;br /&gt;</pre></div></div>

<p>As in my previous post you need to put what ever will be shown or hidden in a div class tag.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;div_class_name&quot; style=&quot;display: none;&quot;&gt;</pre></div></div>

<p>The style hides everything in the class until the box is checked.</p>
<p>That will start the boxed checked, when you un-check it the data in all div classes with that name will hide (remember the &#8216;div_class_name&#8217;? that&#8217;s what we are working with).</p>
<p>I wrote this up in just a couple minutes, so I truly help it makes scene. You can check out an example of how it works <a href="http://www.tangorangers.com/examples/jshidedivs_part2/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tangorangers.com/2009/08/using-javascript-to-hide-singlemultiple-div-tags-with-the-same-name-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dynamically add form fields using javascript and DOM with dynamic post method</title>
		<link>http://blog.tangorangers.com/2009/05/dynamically-add-form-fields-using-javascript-and-dom-with-dynamic-post-method/</link>
		<comments>http://blog.tangorangers.com/2009/05/dynamically-add-form-fields-using-javascript-and-dom-with-dynamic-post-method/#comments</comments>
		<pubDate>Wed, 06 May 2009 01:14:39 +0000</pubDate>
		<dc:creator>DaijoubuKun</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.tangorangers.com/?p=120</guid>
		<description><![CDATA[Lets say you need to add some extra text fields but you don&#8217;t want to write a bunch of code. I not only have how to quickly and easily add the input fields, but also how to take the data and put in into a MySQL DB! I start with creating the DB. Lets call [...]]]></description>
			<content:encoded><![CDATA[<p>Lets say you need to add some extra text fields but you don&#8217;t want to write a bunch of code.  I not only have how to quickly and easily add the input fields, but also how to take the data and put in into a MySQL DB!</p>
<p>I start with creating the DB.  Lets call the table &#8216;phone&#8217;.  We need 3 rows.  &#8216;idx&#8217; int(10) with Auto Increment and primary key. &#8216;name&#8217; varchar(30), and &#8216;numb&#8217; varchar(20).  You can setup the db how ever you choose.  I create the idx so that I have a key field.</p>
<p>Now we need some javascript.</p>

<div class="wp_syntax"><div class="code"><pre class="javascipt" style="font-family:monospace;">var counter = 0;
Start a counter. Yes, at 0
function add_phone() {
    counter++;
// I find it easier to start the incrementing of the counter here.
    var newFields = document.getElementById('add_phone').cloneNode(true);
    newFields.id = '';
    newFields.style.display = 'block';
    var newField = newFields.childNodes;
    for (var i=0;i&lt;newField.length;i++) {
        var theName = newField[i].name
        if (theName)
                newField[i].name = theName + counter;
// This will change the 'name' field by adding an auto incrementing number at the end. This is important.
        }
        var insertHere = document.getElementById('add_phone');
// Inside the getElementById brackets is the name of the div class you will use.
        insertHere.parentNode.insertBefore(newFields,insertHere);
}</pre></div></div>

<p>Now I like to put that in a seperate .js file, but you can add it to your HTML HEAD tag.</p>
<p>Next we need to build the form.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form name=&quot;add_a_phone&quot; action=&quot;&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
&lt;fieldset&gt;
&lt;div id=&quot;phone&quot;&gt;
    &lt;input type=&quot;text&quot; name=&quot;phone_0&quot; value=&quot;&quot; /&gt;
    &lt;input type=&quot;text&quot; name=&quot;phone_num_0&quot; value=&quot;&quot; /&gt;&lt;br&gt;
&lt;/div&gt;
&lt;div id=&quot;add_phone&quot; style=&quot;display: none;&quot;&gt;
    &lt;input type=&quot;text&quot; name=&quot;phone_&quot; value=&quot;&quot; /&gt;
    &lt;input type=&quot;text&quot; name=&quot;phone_num_&quot; value=&quot;&quot; /&gt;&lt;br&gt;
&lt;/div&gt;
&lt;input type=&quot;button&quot; id=&quot;add_phone()&quot; onclick=&quot;add_phone()&quot; value=&quot;Give me more fields!&quot; /&gt;&lt;br&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;submit&quot; /&gt;
&lt;/fieldset&gt;
&lt;/form&gt;</pre></div></div>

<p>Notice how in the input button field that the &#8216;id&#8217; and &#8216;onclick&#8217; are the same. That&#8217;s important, and yes you do need the brackets for some reason.<br />
Also note that the form name can NOT be the same as any div id!!! I keep making that mistake.<br />
You will need some way of checking how many fields were added when you get to your &#8216;if(isset($_POST[&#8216;submit&#8217;))&#8217; statement. This gets a little messy.<br />
Because I like my forms to go back to this page and check if submit was clicked we need to put some php code at the very top.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'submit'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;You clicked submit!&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Here is your data&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'phone_num_0'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$continue</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$continue</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'phone_'</span><span style="color: #339933;">.</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#123;</span>
                    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'phone_'</span><span style="color: #339933;">.</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; = &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'phone_num_'</span><span style="color: #339933;">.</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$phone</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'phone_'</span><span style="color: #339933;">.</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$phone_num</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'phone_num_'</span><span style="color: #339933;">.</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO phone (idx, name, numb) VALUES ('NULL', '<span style="color: #006699; font-weight: bold;">$phone</span>', '<span style="color: #006699; font-weight: bold;">$phone_num</span>')&quot;</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #b1b100;">else</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$continue</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Obviously I left out some information.  Like connecting to your DB.  I&#8217;m assuming you already know how to do that.</p>
<p>I first wrote this on my main page.  This post is almost a copy/paste from the main page. I like adding it to the blog since it gets better indexing from search engines and hopefully the information will be useful to you.  On the main page there is also a working example so you can see how it all ties in.  Check it out <a href="http://www.tangorangers.com/examples/dynadddynpost/index.php">Here</a></p>
<p>Questions?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tangorangers.com/2009/05/dynamically-add-form-fields-using-javascript-and-dom-with-dynamic-post-method/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Using Javascript to hide single/multiple div tags with the same name</title>
		<link>http://blog.tangorangers.com/2009/03/using-javascript-to-hide-singlemultiple-div-tags-with-the-same-name/</link>
		<comments>http://blog.tangorangers.com/2009/03/using-javascript-to-hide-singlemultiple-div-tags-with-the-same-name/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 16:49:39 +0000</pubDate>
		<dc:creator>DaijoubuKun</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[div]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.tangorangers.com/?p=104</guid>
		<description><![CDATA[Update (March 25th, 2009): I have created a page on the main site so that you can see how the code works, it may be easier to read than this. Check it out here After scouring the net for information I finally got my answer from JimmySeal at TechGuy.org. Turns out the process is very [...]]]></description>
			<content:encoded><![CDATA[<p>Update (March 25th, 2009):<br />
I have created a page on the main site so that you can see how the code works, it may be easier to read than this.  Check it out <a href="http://www.tangorangers.com/examples/jshidedivs/">here</a></p>
<p>After scouring the net for information I finally got my answer from JimmySeal at <a href="http://forums.techguy.org">TechGuy.org</a>.  Turns out the process is very simple.</p>
<p>In my first example I want to hide just one div tag when a check box is clicked. The process is a simple one, all we need to do is create a div with an id argument.  Like <em>div id=&#8221;hideme&#8221;</em>.  I prefer to use external js files to hold my javascript functions.  Lets call it <em>junctions.js</em>.  In this file lets put this bit of code.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> toggle_visibility<span style="color: #009900;">&#40;</span>hideme<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> e <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>hideme<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'block'</span><span style="color: #009900;">&#41;</span>
		e.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'none'</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">else</span>
		e.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'block'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This will hide the div tag with id <em>hideme</em><br />
So in my html file I have something like this.  (My example is in an input form)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>b<span style="color: #339933;">&gt;</span>Show the field<span style="color: #339933;">&lt;/</span>b<span style="color: #339933;">&gt;&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;a_name&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;a_name&quot;</span> onClick<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;toggle_visibility('hideme');&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hideme&quot;</span> style<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;display:block;&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>b<span style="color: #339933;">&gt;</span>was hidden<span style="color: #339933;">&lt;/</span>b<span style="color: #339933;">&gt;&lt;</span>textarea name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;some_name&quot;</span> cols<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;40&quot;</span> rows<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;5&quot;</span><span style="color: #339933;">&gt;&lt;/</span>textarea<span style="color: #339933;">&gt;&lt;</span>br <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Notice that the div id and the onClick functions are the same name, <em>hideme</em>.  That&#8217;s it!  How when the box is checked it will hide that one div tag.</p>
<p>What if you want to hide multiple div tags.  Unfortunately the above script will not work simply because you can&#8217;t have more than one div id per page.  You must use <strong>div class</strong>.</p>
<p>Open up your functions.js file and put this in.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> hidden <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">function</span> getElementsByClass<span style="color: #009900;">&#40;</span>searchClass<span style="color: #339933;">,</span> domNode<span style="color: #339933;">,</span> tagName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>domNode <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> domNode <span style="color: #339933;">=</span> document<span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>tagName <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> tagName <span style="color: #339933;">=</span> <span style="color: #3366CC;">'*'</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> el <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> tags <span style="color: #339933;">=</span> domNode.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span>tagName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> tcl <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot; &quot;</span><span style="color: #339933;">+</span>searchClass<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot; &quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>j<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>tags.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> test <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot; &quot;</span> <span style="color: #339933;">+</span> tags<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">className</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; &quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>test.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span>tcl<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>
		el<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> tags<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> el<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> toggle_hideme<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	hidden <span style="color: #339933;">=</span> <span style="color: #339933;">!</span>hidden<span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> newDisplay<span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>hidden<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		newDisplay <span style="color: #339933;">=</span> <span style="color: #3366CC;">'none'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">else</span>
	<span style="color: #009900;">&#123;</span>
		newDisplay <span style="color: #339933;">=</span> <span style="color: #3366CC;">'block'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #003366; font-weight: bold;">var</span> hellos <span style="color: #339933;">=</span> getElementsByClass<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div_class_name&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;div&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> hellos.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		hellos<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span> <span style="color: #339933;">=</span> newDisplay<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now for the form code example</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;a_name&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;a_name&quot;</span> onClick<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;toggle_hideme('div_class_name');&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;div_class_name&quot;</span><span style="color: #339933;">&gt;</span>
	Blah Blah Blah
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;something_else&quot;</span><span style="color: #339933;">&gt;</span>
	What ever is here will not disappear<span style="color: #339933;">!</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;div_class_name&quot;</span><span style="color: #339933;">&gt;</span>
	more blah blah blah
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The only thing you need to pay attention to here is <em>div_class_name</em> just change it to what ever you want to call your div tag.</p>
<p>EDIT NOTE:<br />
I just want to say that I&#8217;ve been getting a lot of hits here, but no one leaves me any comments. How do I know if this is helpful?  Please leave a comment.  I won&#8217;t sell your e-mails or anything.  If you so desire enter in a fake e-mail, I don&#8217;t care.  I just want to know.  Thank you.</p>
<p>UPDATE!<br />
<a href="http://blog.tangorangers.com/2009/08/using-javascript-to-hide-singlemultiple-div-tags-with-the-same-name-part-2/">http://blog.tangorangers.com/2009/08/using-javascript-to-hide-singlemultiple-div-tags-with-the-same-name-part-2/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tangorangers.com/2009/03/using-javascript-to-hide-singlemultiple-div-tags-with-the-same-name/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Insert MySQL query in php with NULL</title>
		<link>http://blog.tangorangers.com/2009/02/insert-mysql-query-in-php-with-null/</link>
		<comments>http://blog.tangorangers.com/2009/02/insert-mysql-query-in-php-with-null/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 14:11:29 +0000</pubDate>
		<dc:creator>DaijoubuKun</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.tangorangers.com/?p=81</guid>
		<description><![CDATA[EDIT: 03/01/2009 NOTE! This may not be good practice. There are better ways to inserting a TRUE NULL value! This actually inserts the word NULL in the database! You may have to look over your final code and determine if my way was the best way. Also, you only have to do this if you [...]]]></description>
			<content:encoded><![CDATA[<p>EDIT:  03/01/2009<br />
NOTE!  This may not be good practice.  There are better ways to inserting a <strong>TRUE</strong> <em>NULL </em>value!  This actually inserts the word NULL in the database!  You may have to look over your final code and determine if my way was the best way.  Also, you only have to do this if you have issues trying to insert the data into MySQL.<br />
End Edit.</p>
<p>The only way this post will help you is if in your MySQL database you have <em>NULL</em> set to <em>YES</em> and <em>DEFAULT</em> as <em>NULL</em>.  Most databases are not setup this way, it&#8217;s probably pretty rare.  See end of post.</p>
<p>Recently I ran into an issue with my php script that inserts data into MySQL that has NULL fields.  Here is how I fixed it.</p>
<p>To start in my database I have fields that can accept a <em>NULL</em> value, because of this I had to change the way my data was entered into the database.  After I created a form to take the data I then ran it through a process to add slashes (in case there were any single quotes, double quotes, or any other non standard character).</p>
<p>For example, I have a field called <em>title</em> in my database, and in my form.  Now lets say that the user of the script doesn&#8217;t enter in a title but we still want to insert a record.  I need to first determine that there is or is not any data.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;NULL&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Notice that I put <em>NULL</em> in quotations.  If you do not quote it you will clear out the variable.  This will cause issues in the <em>INSERT</em> query to MySQL.</p>
<p>The MySQL query might look something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO table_name (name, title) VALUES ('<span style="color: #006699; font-weight: bold;">$name</span>', '<span style="color: #006699; font-weight: bold;">$title</span>')&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I know this doesn&#8217;t make much sense, but it&#8217;s the way I had to do it because of the way my database was setup.  Here is the entire php file.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'submit'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;NULL&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO table_name (name, title) VALUES ('<span style="color: #006699; font-weight: bold;">$name</span>', '<span style="color: #006699; font-weight: bold;">$title</span>')&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Enter a Name!&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;form name=&quot;form1&quot; action = &quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; method=&quot;post&quot; enctype='multipart/form-data'&gt;
     &lt;input name=&quot;name&quot; type=&quot;text&quot; value=&quot;name&quot; /&gt;
     &lt;input name=&quot;title&quot; type=&quot;text&quot; value=&quot;title&quot; /&gt;
     &lt;input name=&quot;submit&quot; type=&quot;submit&quot; value=&quot;submit&quot; /&gt;
&lt;/form&gt;</pre></div></div>

<p>In the Database, using something like <a href="http://www.phpmyadmin.net/home_page/index.php" target="_blank">PHPMyAdmin <img src="http://www.tangorangers.com/extlink.gif" alt="External popup link" /></a> you might see something like this.</p>
<p>Field&#8212;&#8212;&#8212;-Type&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;Collation&#8212;&#8212;&#8212;Attributes&#8212;&#8212;Null&#8212;&#8212;Default&#8212;&#8212;Extra<br />
name&#8212;&#8212;-varchar(30)&#8212;-utf8_unicode_ci&#8212;&#8212;&#8211;None&#8212;&#8212;&#8212;-No<br />
title&#8212;&#8212;&#8212;varchar(30)&#8212;-utf8_unicode_ci&#8212;&#8212;&#8211;None&#8212;&#8212;&#8212;-Yes&#8212;&#8212;&#8211;NULL</p>
<p>If so you will need to quote your <em>NULL</em> before inserting the data into MySQL. (Sorry that doesn&#8217;t line up very well)<br />
Maybe this way will help.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tangorangers.com/2009/02/insert-mysql-query-in-php-with-null/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using PHP to upload an image and rename it.</title>
		<link>http://blog.tangorangers.com/2009/01/using-php-to-upload-an-image-and-rename-it/</link>
		<comments>http://blog.tangorangers.com/2009/01/using-php-to-upload-an-image-and-rename-it/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 05:37:53 +0000</pubDate>
		<dc:creator>DaijoubuKun</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.tangorangers.com/?p=40</guid>
		<description><![CDATA[If your like me you have scoured the internet trying to find a simple php script that will let a user upload an image and then rename the image to something unique. Well I have just the solution. First, the only real requirement is PHP and a web server (I use Apache). Create a new [...]]]></description>
			<content:encoded><![CDATA[<p>If your like me you have scoured the internet trying to find a simple php script that will let a user upload an image and then rename the image to something unique.  Well I have just the solution.</p>
<p>First, the only real requirement is PHP and a web server (I use Apache).</p>
<p>Create a new file, lets call it &#8216;image_upload.php&#8217;<br />
At the bottom of the page we are going to put in a basic form to give a browse and upload button.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>form action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;./image_upload.php&quot;</span> enctype<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;multipart/form-data&quot;</span> method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span><span style="color: #339933;">&gt;</span>
Select Image to upload
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;thefile&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;file&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;upload&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The form name isn&#8217;t important. The action is.  That is the name of the file that needs to be accessed when the upload button is clicked.<br />
Input type is very important, and so is the name.</p>
<p>Now that we have a starting point go to the top of the file.  Just to make it easy I&#8217;m going to paste the entire code here then explain it part by part.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'submit'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000088;">$tmp_name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'thefile'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$newarray</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'thefile'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$thecount</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$newarray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$fileprefix</span> <span style="color: #339933;">=</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;.&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$newarray</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$thecount</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">move_uploaded_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp_name</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;../img/<span style="color: #006699; font-weight: bold;">$fileprefix</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>To start the if statement at the top is to ensure that the &#8216;submit&#8217; button was hit before running the script.<br />
The &#8216;<em>$tmp_name</em>&#8216; variable is used to get rid of that damn array.<br />
<em>$newarray</em> takes the file&#8217;s real name (see note below) and explodes the array into several smaller arrays by the &#8216;.&#8217;. For example, if the file uploaded it called &#8216;best.friends.pic.jpg&#8217; it breaks that name up to &#8216;best&#8217;, &#8216;friends&#8217;, &#8216;pic&#8217;, and &#8216;jpg&#8217;.  Trust me, this is important (If you don&#8217;t understand how arrays work I recommend doing some research and learning).<br />
The next line I use the <em>count</em> function. This will help in the event there is more than one &#8216;.&#8217; in the name of the file being uploaded.<br />
Now to create the new name of the file.  <em>$fileprefix</em> equals the time of the upload.  This works well, it will grab the time from the server and use it for the file name.  Then it adds a &#8216;.&#8217;, then adds the suffix of the file (example: jpg)<br />
Time to move the uploaded file.  In my example I added the directory before the newly created file name. This will go back 1 directory and then to &#8216;<em>img/</em>&#8216;.<br />
Lastly, we use the &#8216;<em>exit();</em>&#8216; function.  This is so that after the file has been uploaded the script stops.  If you remove the function it will display the upload form again.</p>
<p>NOTE:  There is a reason (altho I don&#8217;t know it) on why there are 2 arrays.  It seems to me that the first (<em>$_FILES['thefile']['tmp_name']</em>) holds 2 parts, a pointer for &#8216;<em>thefile</em>&#8216; and the temp name php gives files before we do something with it, and the second (<em>$_FILES['thefile']['name']</em>) contains the original name of the file.</p>
<p>btw, make sure apache has full access to the folder you are uploading images to.<br />
For example, if this is on your own server check /etc/apache.conf (or httpd.conf) for the user and group apache runs under.  This is usually either &#8216;<em>nobody</em>&#8216; or &#8216;<em>apache</em>&#8216;.<br />
If you have SSH into your server (or are sitting infront of it) goto the directory your files are being sent to and type</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chown</span> apache.apache img<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-R</span></pre></div></div>

<p>This will give both user and group &#8216;<em>apache</em>&#8216; access to write files.</p>
<p>p.s.  I will be creating another script here that deals with multiple picture uploads.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tangorangers.com/2009/01/using-php-to-upload-an-image-and-rename-it/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My new rss mini news feed</title>
		<link>http://blog.tangorangers.com/2008/11/my-new-rss-mini-news-feed/</link>
		<comments>http://blog.tangorangers.com/2008/11/my-new-rss-mini-news-feed/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 03:37:27 +0000</pubDate>
		<dc:creator>DaijoubuKun</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://blog.tangorangers.com/?p=10</guid>
		<description><![CDATA[