<?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&#039;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>Wed, 18 Jan 2012 02:26:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How To Update a Live Website via SVN</title>
		<link>http://blog.tangorangers.com/2012/01/how-to-update-a-live-website-via-svn/</link>
		<comments>http://blog.tangorangers.com/2012/01/how-to-update-a-live-website-via-svn/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 02:26:16 +0000</pubDate>
		<dc:creator>DaijoubuKun</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[good to know]]></category>

		<guid isPermaLink="false">http://blog.tangorangers.com/?p=372</guid>
		<description><![CDATA[Do you want to use SVN to update your website? This guide will help you and includes information not found anywhere else on how to get it working. Many websites give basic information and comments complain about it not working. If those other website didn&#8217;t work for you. This will. After digging around for hours [...]]]></description>
			<content:encoded><![CDATA[<p>Do you want to use SVN to update your website? This guide will help you and includes information not found anywhere else on how to get it working. Many websites give basic information and comments complain about it not working. If those other website didn&#8217;t work for you. This will.</p>
<p>After digging around for hours and seeing everyone complain about having the same problems after being told the same solutions, I decided to figure it out for myself. If you read this carefully you too will have a website setup that can be updated via subversion.</p>
<h3><font color='black'>Getting Started</font></h3>
<p>I&#8217;m going to assume that your SVN server and website are on the same machine and that you are using Apache to serve both. I&#8217;m also going to assume that you are somewhat familiar with SVN and Apache. I&#8217;m not going to go into much detail on how to get everything setup from scratch.</p>
<p>The tools you will need to have installed are as follows (may need more depending on your configuration). Apache HTTPd, Subversion, and gcc.</p>
<p>Many Linux users and distributions use sudo. I do not, and I will not provide information on how to use sudo. My recommendation, before doing anything, is to type <b>sudo su</b> which will make you root. Do everything from there so you don&#8217;t have to sudo anymore.</p>
<h3><font color='black'>Setup a new SVN repository</font></h3>
<p>Alright, now we are going to setup the new SVN repository. This can be done easily with:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">svnadmin create &lt;path to repository&gt;</pre></div></div>

<p>Place it in a good location that you will remember since you need to point Apache to it. In my examples we are going to use <b>/home/www/domain/svn/website/</b> for our project location and <b>/home/www/domain/htdocs/</b> for our website.</p>
<p>For user access controls I use a 2 part process. I have an authz and passwd file in the root of my SVN directory (/home/www/domain/svn/). The reason I do this is because I host several SVN projects and I don&#8217;t want everyone to have access to everything. This way I can also setup (this comes later) Apache to have read-only access to the repository.</p>
<p>First, we need to create our authz and passwd files. Lets call them svn.authz and svn.passwd so we know what they are for.</p>
<p>In the svn.authz file we need something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[groups]
project = dkun
other1 = dkun, someguy
website = dkun, friend1
readonly = redmine,apache
&nbsp;
[project:/]
@project = rw
@readonly = r
* =
&nbsp;
[other1:/]
@other1 = rw
* =
&nbsp;
[website:/]
@website = rw
@readonly = r
* =</pre></div></div>

<p>Looks a bit overwhelming. Let me explain.</p>
<p>Starting from the top, we have <b>[groups]</b>. These are groups of users that we give project names to. Notice that 2 of the projects have more that one user. There is also a read-only group. You can name the groups what every you want. I do it by project name to make it easy to read.</p>
<p>After that you see <b>[project:/]</b>. This is the project group. It has one user and is set to read/write. It also has a readonly group. This way I can setup both Apache and Redmine with read only access.</p>
<p>Lastly you might have noticed <b>*=</b>. What is that? It turns off anonymous access. So unless your project has code going out to the web, make sure to put this in.</p>
<p>Now we need to setup the svn.passwd file. This is pretty easy. Just type:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">htpasswd svn.passwd &lt;username&gt;</pre></div></div>

<p>You will be prompted for the password. That&#8217;s it! Pretty easy right? Just don&#8217;t forget to setup the user apache (keep it lower case, trust me), and any others you might need.</p>
<h3><font color='black'>Setup Apache</font></h3>
<p>Now that we have SVN and out new project setup, we need to configure Apache to serve everything. Setup your <b>VirtualHost</b> to point to where you want your website to be hosted from. So for me it would be <b>/home/www/domain/htdocs/</b>. I&#8217;m going to assume you already know how to do this. All you need to add is a little directive.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&lt;DirectoryMatch &quot;^/.*/\.svn/&quot;&gt;
     Order deny,allow
     Deny from all
&lt;/DirectoryMatch&gt;</pre></div></div>

<p>This will stop someone from browsing your .svn folder on the website.</p>
<p>Now setup an SVN VirtualHost. This gets a bit more complicated. I&#8217;m going to avoid going into detail here. I want to assume you have some background.</p>
<p>In your Virtual host we need to set a few options and point to the SVN repository root. Here is an example of the options you need to put inside the VirtualHost section for SVN to work. Don&#8217;t forget to set other items you need!</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&lt;Location /svn&gt;
   DAV svn
   SVNParentPath /home/www/domain/svn
   AuthType Basic
   AuthName &quot;My SVN Repository&quot;
   AuthUserFile /home/www/domain/svn/svn.passwd
   AuthzSVNAccessFile /home/www/domain/svn/svn.authz
   Require valid-user
&lt;/Location&gt;
&lt;Directory /home/www/domain/svn&gt;
   Options +Indexes FollowSymLinks +ExecCGI
   AllowOverride AuthConfig FileInfo
   Order allow,deny
   Allow from all
&lt;/Directory&gt;</pre></div></div>

<p>Note all the directories. Change them to match your server. Also, verify that your SVN modules are enabled in Apache. They should be in your apache.conf or httpd.conf (depending on your server). You will need to enable:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">LoadModule dav_svn_module lib/httpd/modules/mod_dav_svn.so
LoadModule authz_svn_module lib/httpd/modules/mod_authz_svn.so</pre></div></div>

<p>That&#8217;s it! Now type <b>apachectl configtest</b> and you will get messages back if there is a problem in your Apache config. If it is a warning about your website directory missing, don&#8217;t worry. Just create the directory and give full ownership to the apache user (We will get back to this in a moment).</p>
<p>Before continuing, restart Apache with <b>apachectl restart</b> and make sure your SVN works! If it does not then the next section will fail.</p>
<h3><font color='black'>Do some weird stuff with Apache</font></h3>
<p>Here is where things get a little weird. This is also where 99% of people fail because there is no good information out there. I will do my best to explain what to do and why you should do it.</p>
<p>The first step is you need to find out what user and group Apache runs under. For me, both are <b>apache</b>, but for you it could use <b>www</b> or <b>www-user</b>. You can find this by checking <b>/etc/passwd</b> and <b>/etc/group</b>, or by going through your apache.conf file and look for <b>User</b> and <b>Group</b> directives.</p>
<p>Now look in /etc/passwd for the apache user. The second to last option shows Apache&#8217;s  home directory. In my case it is <b>/srv/httpd</b>. Go to that directory and type:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">chown apache.apache ./</pre></div></div>

<p>Set the user and group to which ever Apache runs under. This will allow Apache to create new directories there without changing ownership of anything else. Also, that is just one (1) period before the slash!</p>
<p>Open /etc/passwd and find the apache user again. At the end of the line you should see something like <b>/bin/false</b>. This keeps the Apache user from logging in. This is for security reasons. We are going to temporarily change it to <b>/bin/bash</b>.</p>
<p>Now that you are already root, type:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">su – apache</pre></div></div>

<p>Once again I assume your Apache&#8217;s user is apache. Adjust as needed.</p>
<p>Now you are logged in as the Apache user. You should see a new shell and be ready to go. Make sure you are in the <b>/var/httpd</b> directory (as stated previously as being Apache&#8217;s home directory) by typing <b>pwd</b>. If you are, then you have created a new session and are ready for the next step.</p>
<p>Navigate to the directory where the website will be served from. So if the website is in <b>/home/www/domain/htdocs/</b> then go one level up; <b>/home/www/domain/</b>. Now we are going to perform an SVN checkout and have subversion remember our credentials.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">svn co http://&lt;domain&gt;/svn/website</pre></div></div>

<p>Adjust the http directive as needed. If you use SSL have subversion permanently accept the certificate. You should see a prompt for apache&#8217;s password. This is the password you created for it in svn.passwd. Type it in and when asked if you want to store the password, say yes!</p>
<p>If everything went as planned then you should see a successful checkout as revision 0. If not&#8230; well you did something wrong. Double check your paths, apache config files, and passwords. If needed, you may need to give ownership of the directory to Apache so that user can create a new directory and write to it.</p>
<p>Check to make sure a <b>.subversion</b> directory was created in Apache&#8217;s home directory and that there is a <b>.svn</b> folder in <b>/home/www/domain/htdocs/</b>. If now you need to give ownership of that directory to the Apache user (you will have to be root for this). If there is so .svn directory, then change ownership of the htdocs directory to Apache and run the checkout again.</p>
<p>If everything went smoothly then we are done as the Apache user. Type <b>logout</b> to return to being root.</p>
<p>Last thing. Open up <b>/etc/passwd</b> and change <b>/bin/bash</b> back to <b>/bin/false</b>. No need to have a security hole.</p>
<h3><font color='black'>Create an executable</font></h3>
<p>Now that we have SVN, Apache, and a SVN checkout setup, we can finally finish this. The first thing you need to do is find where svn is located:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">whereis svn
svn: /usr/bin/svn /usr/man/man1/svn.1.gz /usr/share/man/man1/svn.1.gz</pre></div></div>

<p>As you can see, I used <b>whereis</b> to find the svn executable. It&#8217;s the first one, /usr/bin/svn.</p>
<p>Navigate over to the htdocs directory. Open up your favorite text editor and dump this in it:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stddef.h&gt;</span>
<span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include &lt;unistd.h&gt;</span>
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   execl<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/usr/bin/svn&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;svn&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;update&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;/home/www/domain/htdocs/&quot;</span><span style="color: #339933;">,</span>
      <span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span>EXIT_FAILURE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>See where the directives of <b>/usr/bin/svn</b> and <b>/home/www/domain/htdocs/</b> are? Just change those to match your server. Save the file as <b>update.c</b> and just back to the shell.<br />
Now we need to compile the program:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">cc -o update update.c</pre></div></div>

<p>This will create an executable called update. You can call it what ever you want, just as long as before renaming it you type <b>chown apache.apache update; chmod +s update</b>. It should be owned by the Apache user.</p>
<h3><font color='black'>Setup post-commit</font></h3>
<p>Just over to your SVN repository, then into the hooks directory. So if you were following, <b>cd /home/www/domain/svn/website/hooks</b>. There you will see a bunch of .tmpl files. Rename of copy <b>post-commit.tmpl</b> to <b>post-commit</b>, then chmod 755 post-commit.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">cp post-commit.tmpl post-commit
chmod 755 post-commit</pre></div></div>

<p>Open post-commit in your editor. You may see a bunch of stuff in there. Just put a hash (#) sign in front of any other commands there. They are examples. Add:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">/home/www/domain/htdocs/update</pre></div></div>

<p>That&#8217;s it. Don&#8217;t add sh, or bash to the front, just put in the path with executable at the end. Save and exit.</p>
<h3><font color='black'>Try it!</font></h3>
<p>Now, as long as you followed along and I didn&#8217;t skip anything. This should work. Try it out. Try committing something to SVN and see what happens! If you can view the website right away, they you did it correctly. If now, you should check your apache log files. Specifically <b>error_log</b>. If SVN threw an error you will have to see what went wrong there. Sometimes just putting a commit message in will fix any error.</p>
<p>That&#8217;s it. I hope you found this informative. Please feel free to drop my a comment below if you have anything you wish to add or just want to say thanks for the info. I appreciate all feedback. Thanks for reading!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tangorangers.com/2012/01/how-to-update-a-live-website-via-svn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use Redmine when your Ruby is too new</title>
		<link>http://blog.tangorangers.com/2011/12/how-to-use-redmine-when-your-ruby-is-too-new/</link>
		<comments>http://blog.tangorangers.com/2011/12/how-to-use-redmine-when-your-ruby-is-too-new/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 04:21:19 +0000</pubDate>
		<dc:creator>DaijoubuKun</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[good to know]]></category>
		<category><![CDATA[hacks]]></category>

		<guid isPermaLink="false">http://blog.tangorangers.com/?p=334</guid>
		<description><![CDATA[Recently my work switched to Redmine to keep track of our projects and such, I loved it so much, I wanted to use it at home for my personal projects. Seriously, if you have never used it, give it a try, you won&#8217;t be disappointed. However, there is a problem that I ran into when [...]]]></description>
			<content:encoded><![CDATA[<p>Recently my work switched to <a href="http://redmine.org" title="Redmine" target="_blank">Redmine</a> to keep track of our projects and such, I loved it so much, I wanted to use it at home for my personal projects. Seriously, if you have never used it, give it a try, you won&#8217;t be disappointed. However, there is a problem that I ran into when setting it up at home, my Ruby was too new! At the time of this writing Redmine version 1.2.2 was the current stable, and required Ruby 1.8.6 or 1.8.7. My server came with 1.9.1! I could either downgrade and risk possible incompatibility problems, or I could take another approach. After days of Goggling, I found a solution.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Check out https://rvm.beginrescueend.com/rvm/install/</pre></div></div>

<p>I recommend the single user install. I did it with no problems. Things get a bit tricky when using RVM, so I decided to create this Quick and Dirty Guide.</p>
<h3><font color='black'>How to Install and Setup Redmine with RVM</font></h3>
<p>Be sure to pay attention to directories, I will make notes to help make things easy. Also, I recommend trying this out in a VM or a dev box. Please read the HowTos on redmine.org and do some research and testing before following this guide.</p>
<p>Note: This was done running Slackware 13.1. I do NOT use sudo on my machines. If you get a permissions error you can use sudo if your Linux distro is setup for it. The first part of this I did as the root user. If you use sudo, type <strong>&#8216;sudo su -&#8217;</strong> to become full root. If you see Redmine (with the capital R), I&#8217;m referring to the Redmine program or website. Lowercase, is the user redmine.</p>
<p>After downloading the source from redmine.org extract it and rename the folder to redmine, you don&#8217;t have to do this, it&#8217;s just how I did it.</p>
<p><strong>Setup a Redmine user</strong></p>
<p>This user doesn&#8217;t need remote access, or the ability to login directly. We are going to create a new user and group for Redmine to run under.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">groupadd redmine
useradd redmine -g redmine -m</pre></div></div>

<p>Now set permission to where you extracted Redmine to. We are going to give everything to the redmine user and group.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">chown redmine:redmine redmine/ -R</pre></div></div>

<p>Now you need to <strong>su &#8211; redmine</strong>. Make sure you are in the redmine user&#8217;s home directory. Usually /home/redmine/</p>
<p><strong>Setup RVM</strong></p>
<p>Now that you are the redmine user and in their home directory, it&#8217;s time to install RVM. Be sure to check out their <a href="https://rvm.beginrescueend.com/rvm/install/" title="RVM install information" target="_blank">website</a> for full and up to date information. The information listed here maybe out of date!</p>
<p>Lets install RVM for single user use. You are welcome to use the multi-user version, but this way worked just fine for me. Once again, make sure you are in the redmine user&#8217;s home directory.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">bash &lt; &lt;(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )</pre></div></div>

<p>This will get the installer going. Once it finishes, run this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">echo '[[ -s &quot;$HOME/.rvm/scripts/rvm&quot; ]] &amp;&amp; . &quot;$HOME/.rvm/scripts/rvm&quot; # Load RVM function' &gt;&gt; ~/.bash_profile</pre></div></div>

<p>Now logout. Log back in as the redmine user. and type:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">type rvm | head -1</pre></div></div>

<p>You should get back <em>rvm in a function</em>. If not, something went wrong. Try the commands listed above again. If you get an error about a broken pipe, don&#8217;t worry about it. I got it once, but never again. I have no idea why.</p>
<p>If you do get back the good news type:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">rvm install 1.8.7</pre></div></div>

<p>This will install ruby 1.8.7! Once it is complete type:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">rvm use 1.8.7</pre></div></div>

<p>If you don&#8217;t get back any errors, type:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">rvm use 1.8.7 --default</pre></div></div>

<p>This will set that ruby version as your default (only for the redmine user!) RVM is now setup. Good job!</p>
<p><strong>Install Some Ruby Gems</strong></p>
<p>Now that RVM is setup and Ruby 1.8.7 is installed, we need to setup some gems for ruby. First step is getting the correct version of RubyGems installed. As per the Redmine documentation, we want version 1.3.7. I find the easiest way of doing this is to grab their .tgz file. Once you get it (you can also find a list of versions available for download <a href="http://rubyforge.org/frs/?group_id=126" title="RubyGems Download" target="_blank">here.</a> Extract it, and run setup.rb.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz
tar zxf rubygems-1.3.7.tgz
ruby rubygems-1.3.7/setup.rb</pre></div></div>

<p>It should only take a second or two to install. Once it&#8217;s complete there are two more gems that need to be installed before continuing. It is easy and straight forward. Note: If your system appears to freeze when running the commands below, do not worry. It&#8217;s working in the background a may take a minute or two.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">gem install rails -v=2.3.11
gem install -v=0.4.2 i18n</pre></div></div>

<p><strong>Setup MySQL</strong></p>
<p>Assuming you are still the redmine user and MySQL is setup and ready to go, these next steps are very easy and were taken right from Redmine&#8217;s website. Follow the steps below.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">mysql -u root -p
create database redmine character set utf8;
create user 'redmine'@'localhost' identified by 'redpass';
grant all privileges on redmine.* to 'redmine'@'localhost';
flush privileges;</pre></div></div>

<p>Take note of <strong>redpass</strong>. Change it to the password you want to use!</p>
<p>Log out of MySQL and stay logged in as the redmine user. Change directory to where the redmine program is stored. For this example, and the rest of the article, I&#8217;m going to assume it&#8217;s in <strong>/srv/redmine</strong></p>
<p>Copy config/database.yml.example to config/database.yml then edit config/database.yml to include your db setup (under production. You can remove the others)</p>
<p>Copy public/dispatch.cgi.example to public/dispatch.cgi then changes first line to the path of the redmine user&#8217;s ruby location (<strong>/home/redmine/.rvm/bin/ruby</strong> in my case)</p>
<p>public/dispatch.cgi needs to have execute permissions. If it does not, type: <strong>chmod 755 public/dispatch.cgi</strong></p>
<p>Uncomment <strong>NV['RAILS_ENV'] ||= &#8216;production&#8217;</strong> in config/environment.rb</p>
<p>Now we need to setup MySQL access. Below are four (4) commands that will do all this including building the MySQL gem. Please note the path to mysql_config. Make sure this matches your setup!</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">rake generate_session_store
gem install mysql -- --with-mysql-config=/usr/bin/mysql_config
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rake redmine:load_default_data</pre></div></div>

<p>If any of these fail, something may have gone wrong with RVM or MySQL. Check you meet the minimum qualifications listed on Redmine&#8217;s website and your paths are correct.</p>
<p><strong>Setup Passenger</strong></p>
<p>Passenger is designed to run as an apache module to keep Ruby of Rails running. If Redmine isn&#8217;t used for a while, Ruby of Rails may stop running, it&#8217;s not a big deal, it just means it will take a second longer to access your first request. It&#8217;s easy to setup, and can be done as the redmine user. So make sure you are still logged in as your redmine user.</p>
<p>I&#8217;m running version 3.0.11 or Passenger, you are welcome to do the same. There are only three (3) simple steps involved. So I put them below. Just give it some time to build, it can take a few minutes.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">wget http://rubyforge.org/frs/download.php/75548/passenger-3.0.11.tar.gz
tar zxf passenger-3.0.11.tar.gz
./passenger-3.0.11/bin/passenger-install-apache2-module</pre></div></div>

<p>Once the build finishes there are some lines you need to add to your apache.conf file. They are listed above, they are easy to see. Now, depending on your Linux distro, there are several names and locations for this file. You will need root access to edit the Apache config.</p>
<p>At this point you can stop being logged in as the redmine user. Go back to being root (or your regular user with sudo access)</p>
<p><strong>Setup Apache</strong></p>
<p>This setup worked well for me, I would recommend reading up on Apache config options at <a href="http://www.redmine.org/projects/redmine/wiki/HowTo_configure_Apache_to_run_Redmine" title="How to configure apache" target="_blank">http://www.redmine.org/projects/redmine/wiki/HowTo_configure_Apache_to_run_Redmine</a></p>
<p>The page is a little hard to understand when talking about mod_fcgi and mod_fastcgi. You do NOT need them. They maybe faster, but I find that mod_cgi works just fine.</p>
<p>I&#8217;m getting a bit lazy here, and I don&#8217;t feel much like going into a lot of explanation on all the options you can use in Apache. Below is a sample of what I used.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&lt;VirtualHost *:80&gt;
   ServerName redmine.&lt;YOUR-DOMAIN&gt;.com
   ServerAdmin webmaster@&lt;YOUR-DOMAIN&gt;.com
   DocumentRoot /srv/redmine/redmine/public/
   ErrorLog /srv/redmine/redmine/log/redmine_error_log
   &lt;Directory &quot;/srv/redmine/redmine/public/&quot;&gt;
      Options Indexes ExecCGI FollowSymLinks
      Order allow,deny
      Allow from all
      AllowOverride all
   &lt;/Directory&gt;
&lt;/VirtualHost&gt;</pre></div></div>

<p>Obviously there are changes you need to make, like ServerName and ServerAdmin. Note how all the directories start with /srv/redmine/, Update it to where you extracted the Redmine program.</p>
<p><strong>All done!</strong></p>
<p>At this point you should just have to restart apache and you are good to go! Assuming you actually read the Redmine documentation, you can now login as admin (password admin) and give it a go. The first thing I recommend doing is creating a new Admin Level User and removing the default admin. If you get an <em>Internal Error 500</em> when trying to add a new user, then something is definitely wrong. Check the redmine_error_log and production.log file (both should be in the same directory). If you see something about an error with US_ASCII, then Ruby is not running out of the redmine user&#8217;s home directory. Go back through and double check your settings.</p>
<p>I have been told that creating the redmine user in the fashion shown above can create a security risk. As root open /etc/shadow in your favorite editor. At the bottom of the list will be the redmine user. You may see something like:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">redmine:!:12585:0:99999:7:::</pre></div></div>

<p>If you change the exclamation point to an asterisk, it disables the account. That way you can not log into it remotely. Also, if you really want to play it safe, you can edit /etc/passwd also. Just change the last part of the file from /bin/bash to /bin/false. However, by doing this you will not be able to login, or su to that user.</p>
<p><strong>Well?</strong></p>
<p>Did this guide work for you? Do you have any suggestions that may work better? I would love to hear! Feel free to post a comment and let me know how it worked for you, and let me know what Linux distro and version you are running. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tangorangers.com/2011/12/how-to-use-redmine-when-your-ruby-is-too-new/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<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>29</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[A little while ago I decided to build a little rss feed for the main site. This way I could have an area for little news information like new pictures. I use the forum for big news like program releases and this blog for cool stuff. So here we go, this is how I built [...]]]></description>
			<content:encoded><![CDATA[<p>A little while ago I decided to build a little rss feed for the main site.  This way I could have an area for little news information like new pictures.  I use the forum for big news like program releases and this blog for cool stuff.  So here we go, this is how I built my mini news feed.</p>
<p>The entire thing uses a simple MySQL database, apache, php, and some xml code.  To start you MUST edit your mod_php.conf file, look for the line.</p>
<pre lang="" line="">AddType application/x-httpd-php .php .html .htm .xml</pre>
<p>See how I have .xml at the end.  This is because rss feed use xml, if you don&#8217;t add this your php parser will not check your .xml files for php code. Remember you will have to restart your apache server after editing that file.</p>
<p>Now, to make things simple I recommend using <a href="http://www.phpmyadmin.net/home_page/index.php">phpMyAdmin</a> to help you build a database.  After you have installed phpMyAdmin and logged in as root you can create your database.</p>
<p>Once logged in create a new database, lets call it foobar.  Create 2 tables &#8216;admin&#8217; and &#8216;mininews&#8217;.  In admin we need 3 Fields, </p>
<pre lang="" line="1">idx (type 'int(2)', Extra 'auto_increment', put as KEY)
name (type 'tinytext')
pass (type 'tinytext')</pre>
<p>Then under mininews</p>
<pre lang="" line="1">idx (type 'int(100)', Extra 'auto_increment', put as KEY)
news (type 'tinytext')
link (type 'tinytext')
date (type 'timestamp', default 'CURRENT_TIMESPAMP')</pre>
<p>Now go to insert a new record in &#8216;admin&#8217;, idx should start at 0, but it doesn&#8217;t really matter.<br />
Under name, put a username that you will use to insert new records.<br />
Under pass, put a password you want to use.  MAKE SURE YOU SET THE &#8216;FUNCTION&#8217; IS SET TO PASSWORD! THIS WILL ENCRYPT YOUR PASSWORD!</p>
<p>Go back to the main page with phpMyAdmin and click on the &#8216;Privileges&#8217; tab. Then create a new user.  REMEMBER YOUR USERNAME AND PASSWORD, DO NOT USE THE SAME LOGIN AS ABOVE!<br />
Put in a username, localhost, password, and re-type password. Then click Go, do NOT give that user access over the entire server.  On the next screen you can select the database you want the user to have access to, select &#8216;foobar&#8217;.<br />
Only give that user the following privileges under the data area. </p>
<pre lang="" line="">SELECT INSERT and UPDATE.</pre>
<p>Once done with that you may see an option to update server privileges, if not it may have been done already&#8230; I sure hope so.</p>
<p>Now we need some starter php code.  This section is used to insert data into the database from the web browser and NOW with phpMyAdmin (altho you are welcome to use it if you so desire).</p>
<p>Here is my mininews_mysql.php file.  This will connect to the database for reading and writing.</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: #990000;">define</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_USER'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;DB USER&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_PASSWORD'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;DB PASSWORD&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_HOST'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_NAME'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'foobar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dbc</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">mysql_connect</span> <span style="color: #009900;">&#40;</span>DB_HOST<span style="color: #339933;">,</span> DB_USER<span style="color: #339933;">,</span> DB_PASSWORD<span style="color: #009900;">&#41;</span> OR <span style="color: #990000;">die</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Could not connect to mini news feed database '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_select_db</span> <span style="color: #009900;">&#40;</span>DB_NAME<span style="color: #009900;">&#41;</span> OR <span style="color: #990000;">die</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Could not select mini news feed database '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// function for trimming form data</span>
<span style="color: #000000; font-weight: bold;">function</span> escape_data<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$dbc</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">ini_get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'magic_quotes_gpc'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_real_escape_string</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dbc</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// end escape data function</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Now the file used to add a news feed. I call this one mininews_admin.php</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: #666666; font-style: italic;">// if submit</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;">require_once</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./mininews_mysql.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// check that uname and upass work in the db</span>
        <span style="color: #000088;">$uname</span> <span style="color: #339933;">=</span> escape_data<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'uname'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$upass</span> <span style="color: #339933;">=</span> escape_data<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'upass'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT name FROM admin WHERE name='<span style="color: #006699; font-weight: bold;">$uname</span>' AND pass=PASSWORD('<span style="color: #006699; font-weight: bold;">$upass</span>')&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$result</span> <span style="color: #339933;">=</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: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</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: #000088;">$row</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// if a match was made</span>
                <span style="color: #000088;">$news</span> <span style="color: #339933;">=</span> escape_data<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'news'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> escape_data<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #666666; font-style: italic;">// inset data into the database!</span>
                <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO mininews (news, link, date) VALUES ('<span style="color: #006699; font-weight: bold;">$news</span>', '<span style="color: #006699; font-weight: bold;">$link</span>', NOW() )&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$result</span> <span style="color: #339933;">=</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: #666666; font-style: italic;">// run the query</span>
                <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h1&gt;Completed&lt;/h1&gt;&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href='http://www.tangorangers.com/mininews.php'&gt;Go back!&lt;/a&gt;&quot;</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: #666666; font-style: italic;">// if no match was made</span>
                <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;WRONG! If you are not an ADMIN you shouldn't even be trying&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Click &lt;a href='http://www.tangorangers.com'&gt;here&lt;/a&gt; to go home&quot;</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>
&nbsp;
<span style="color: #666666; font-style: italic;">// need auto forward back to mininews.php</span>
        <span style="color: #990000;">ob_end_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// main script</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&lt;HTML&gt;
        &lt;HEAD&gt;
                &lt;TITLE&gt;TangoRangers dev site&lt;/TITLE&gt;
        &lt;/HEAD&gt;
&lt;BODY&gt;
&lt;FORM METHOD='POST' ACTION='./mininews_admin.php'&gt;
&lt;h3&gt;Enter in the fields and be sure to enter username and password to post&lt;/h3&gt;
Title: &lt;INPUT TYPE=&quot;text&quot; NAME=&quot;news&quot; size=40 /&gt;&lt;br /&gt;
Full URL: &lt;INPUT TYPE=&quot;text&quot; NAME=&quot;link&quot; size=40 /&gt;&lt;br /&gt;
&lt;br /&gt;
User Name: &lt;INPUT type=&quot;text&quot; name=&quot;uname&quot; /&gt;&lt;br /&gt;
Password: &lt;INPUT type=&quot;password&quot; name=&quot;upass&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;INPUT type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;submit&quot; /&gt;&lt;br /&gt;
&lt;a href=&quot;./mininews.php&quot;&gt;Go Back&lt;/a&gt;
&lt;/FORM&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;</pre></div></div>

<p>You are free to edit this as you see fit, the only problem I have is after you insert a new feed it shows you what you started with.  It&#8217;s kind of annoying, but I live with it.</p>
<p>Now for the actual rss feed!<br />
To start, edit your index.php/html file and include this example line in your <head> function.</p>
<pre lang="" line="">
<link href="http://www.tangorangers.com/mininews.xml" rel="alternate" title="RSS" type="application/rss+xml">
</pre>
<p>That will add the little rss feed button in the address bar of everyone&#8217;s favorite web browser (*cough* Firefox).</p>
<p>Now create a file called &#8216;mininews.xml&#8217;.  xml is a pretty easy language to work with, it&#8217;s layout is as follows</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>In the actual file you will need to pull data from the database and for that matter, call the mininews_mysql.php file to form the connection to the database.  Here is my file (slightly edited).</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;">require_once</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./mininews_mysql.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT DATE_FORMAT(date, '<span style="color: #009933; font-weight: bold;">%b</span> %D, %Y at %k:%i') AS date, news AS news, link AS link FROM mininews ORDER BY date DESC&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$result</span> <span style="color: #339933;">=</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: #666666; font-style: italic;">//$row = mysql_fetch_array ($result);</span>
        <span style="color: #000088;">$rss</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot; ?&gt;'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$rss</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;rss version=&quot;2.0&quot;&gt;'</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$rss</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;channel&gt;'</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$rss</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;title&gt;Site News&lt;/title&gt;'</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$rss</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;link&gt;http://www.tangorangers.com&lt;/link&gt;'</span><span style="color: #339933;">;</span>
                        <span style="color: #000088;">$rss</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;description&gt;mini news feed&lt;/description&gt;'</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
                        <span style="color: #000088;">$rss</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;
                        &lt;item&gt;
                                &lt;title&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'news'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/title&gt;
                                &lt;link&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/link&gt;
                                &lt;description&gt;on &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'date'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/description&gt;
                        &lt;/item&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
                        <span style="color: #009900;">&#125;</span>
                        <span style="color: #000088;">$rss</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/channel&gt;'</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$rss</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/rss&gt;'</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: text/xml; charset=iso-8859-1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">print</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Now this will pull EVERY feed, no limits, so if you have a lot you may want to add in a limiter.  Look at the $query line, and add &#8216;LIMIT #&#8217; at the end, replace # with the actual number.</p>
<p>And that should do it.  I think, I don&#8217;t think I missed anything, if I did&#8230; oops&#8230; I&#8217;ll fix it.  Until next time  ^_^</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tangorangers.com/2008/11/my-new-rss-mini-news-feed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

