<?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; mysql</title>
	<atom:link href="http://blog.tangorangers.com/tag/mysql/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>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>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>

