<?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>James Tombs &#187; email</title>
	<atom:link href="http://jamestombs.co.uk/tag/email/feed" rel="self" type="application/rss+xml" />
	<link>http://jamestombs.co.uk</link>
	<description>Development blog from James Tombs about PHP, XHTML + CSS and Drupal</description>
	<lastBuildDate>Thu, 11 Mar 2010 09:15:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>[FPSS] Front Page Slideshow for Drupal Update</title>
		<link>http://jamestombs.co.uk/2008-10-24/fpss-front-page-slideshow-for-drupal-update/927</link>
		<comments>http://jamestombs.co.uk/2008-10-24/fpss-front-page-slideshow-for-drupal-update/927#comments</comments>
		<pubDate>Fri, 24 Oct 2008 17:31:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[admin screen]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[be]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[change language]]></category>
		<category><![CDATA[copy paste]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[downloads]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[features change]]></category>
		<category><![CDATA[footer]]></category>
		<category><![CDATA[fpss]]></category>
		<category><![CDATA[french text]]></category>
		<category><![CDATA[front]]></category>
		<category><![CDATA[front page slideshow]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[javascript library]]></category>
		<category><![CDATA[language text]]></category>
		<category><![CDATA[languages]]></category>
		<category><![CDATA[new features]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[openness]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[php file]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[problems]]></category>
		<category><![CDATA[queue]]></category>
		<category><![CDATA[slideshow]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://jamestombs.co.uk/?p=927</guid>
		<description><![CDATA[I have updated my Front Page Slideshow for Drupal module with some new features and some fixes.
New Features:

Change language text within DrupalWithin the admin screen of FPSS you can now add the language text for the slideshow within Drupal which is stored in variables.  By default the module has the English text in.  [...]]]></description>
			<content:encoded><![CDATA[<p>I have updated my Front Page Slideshow for Drupal module with some new features and some fixes.</p>
<p><strong>New Features:</strong></p>
<ul>
<li>Change language text within Drupal<br />Within the admin screen of FPSS you can now add the language text for the slideshow within Drupal which is stored in variables.  By default the module has the English text in.  If you want the French text, then you will have to open up the french.php file and copy paste each item in to the form and save it.</li>
<li>Change javascript location<br />Within the admin screen as well as being able to turn off the javascript library and optimize the javascript you can now selected if you want the javascript to be inserted in to the footer of the page rather than the header.  This is tested and works on a default Drupal installation of 5.12.</li>
</ul>
<p><strong>Fixes</strong></p>
<ul>
<li>Optimize JS and Disable JS both work as expected now and any configuration of the 2 settings should work, although some javascript packages may conflict causing problems.</li>
<li>Fixed the admin settings access, missing array item in hook_perm.</li>
</ul>
<p>You can download the <a href="http://code.google.com/p/fpss-drupal/">fpss for drupal module</a> at the <a href="http://code.google.com/p/fpss-drupal/">Google Code</a> site and you can view the demo of the <a href="http://drupal.jamestombs.co.uk">Front Page Slideshow for Drupal demo</a> at <a href="http://drupal.jamestombs.co.uk">http://drupal.jamestombs.co.uk</a>.</p>
<p>If you have any problems or find any bugs please submit them on the <a href="http://code.google.com/p/fpss-drupal/issues/list">FPSS for Drupal Issue Queue</a> on the Google Code site. Alternatively leave a comment to this post or email at jtombs1987@gmail.com.</p>
]]></content:encoded>
			<wfw:commentRss>http://jamestombs.co.uk/2008-10-24/fpss-front-page-slideshow-for-drupal-update/927/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[PHP + MySQL] Making a basic product database &#8211; Part 1</title>
		<link>http://jamestombs.co.uk/2008-10-12/php-mysql-making-a-basic-product-database-part-1/705</link>
		<comments>http://jamestombs.co.uk/2008-10-12/php-mysql-making-a-basic-product-database-part-1/705#comments</comments>
		<pubDate>Sun, 12 Oct 2008 18:29:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apache php]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[auto increment]]></category>
		<category><![CDATA[automatic id]]></category>
		<category><![CDATA[base]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database management tool]]></category>
		<category><![CDATA[db name]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[fail]]></category>
		<category><![CDATA[host localhost]]></category>
		<category><![CDATA[localhost]]></category>
		<category><![CDATA[my news]]></category>
		<category><![CDATA[my query browser]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[phpmyadmin]]></category>
		<category><![CDATA[product]]></category>
		<category><![CDATA[roots]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[statement]]></category>
		<category><![CDATA[strings]]></category>
		<category><![CDATA[test environment]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[varchar]]></category>
		<category><![CDATA[variables]]></category>
		<category><![CDATA[web folder]]></category>
		<category><![CDATA[web server]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[xxxx]]></category>

		<guid isPermaLink="false">http://jamestombs.co.uk/?p=705</guid>
		<description><![CDATA[
Firstly you need a server which supports PHP and Mysql. If you haven&#8217;t got one, you can set up your computer as a local web server. If you are on Windows, you can follow this guide to help you Set up your PC as a test environment using Apache, PHP and MySQL.
Create the database and [...]]]></description>
			<content:encoded><![CDATA[<div class="amazon"><a href="http://www.amazon.co.uk/PHP-Easy-Steps-Colour/dp/184078282X%3FSubscriptionId%3D02E5W5871AJF7PMMMS82%26tag%3Djamestombs-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D184078282X"><img src="http://ecx.images-amazon.com/images/I/413WS8031EL._SL75_.jpg" /></a></div>
<p>Firstly you need a server which supports PHP and Mysql. If you haven&#8217;t got one, you can set up your computer as a local web server. If you are on Windows, you can follow this guide to help you <a href="http://jamestombs.co.uk/2008-09-22/set-up-your-pc-as-a-test-environment-using-apache-php-and-mysql/634">Set up your PC as a test environment using Apache, PHP and MySQL</a>.</p>
<h2>Create the database and tables</h2>
<p>Open up your database management tool (PHPMyAdmin or command prompt or MySQL Query Browser) and create a new database, I will call mine product_db.</p>
<p>Then we want to create 3 tables. Product, companies and ownership.</p>
<p>The products table will contain 3 fields:</p>
<p>pid &#8211; A unique ID that is automatically generated for us.<br />
name &#8211; The name of the product.<br />
weight &#8211; The weight of the product.</p>
<p>This is the SQL for the table I am creating:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> products <span style="color: #FF00FF;">&#40;</span>
pid <span style="color: #999900; font-weight: bold;">INT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span> <span style="color: #000033;">,</span>
name <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008080;">100</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #000033;">,</span>
weight <span style="color: #999900; font-weight: bold;">FLOAT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>
<span style="color: #FF00FF;">&#41;</span></pre></div></div>

<p>Next up is the companies table which will contain 3 fields.</p>
<p>cid &#8211; A unique ID that is automatically generated for us.<br />
name &#8211; The name of the company.<br />
email &#8211; A contact email address for the company.</p>
<p>This is the SQL for the table I am creating:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> companies <span style="color: #FF00FF;">&#40;</span>
cid <span style="color: #999900; font-weight: bold;">INT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span> <span style="color: #000033;">,</span>
name <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span> <span style="color: #008080;">100</span> <span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #000033;">,</span>
email <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">100</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>
<span style="color: #FF00FF;">&#41;</span></pre></div></div>

<p>The 3rd table is the ownership table which will link up products to companies.</p>
<p>This will contain 2 fields, pid and cid which relate to the automatic ID of the 2 other tables.</p>
<p>This is the SQL for the table I am creating:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> ownership <span style="color: #FF00FF;">&#40;</span>
cid <span style="color: #999900; font-weight: bold;">INT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span>
pid <span style="color: #999900; font-weight: bold;">INT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span>
<span style="color: #FF00FF;">&#41;</span></pre></div></div>

<p>Now that we have the tables set up we can write the PHP to interact with the tables.</p>
<h2>Connecting to the database using PHP</h2>
<p>In your web folder, create a file and call it db_config.php.</p>
<p>In this file we will make the connection to the database.</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: #000088;">$db_host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$db_user</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'root'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$db_pass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'password'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$db_name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'product_db'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db_host</span><span style="color: #339933;">,</span><span style="color: #000088;">$db_user</span><span style="color: #339933;">,</span><span style="color: #000088;">$db_pass</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</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><span style="color: #000088;">$db_name</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</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: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Change the $db_xxxx variables to your database settings.</p>
<p>Save the file and load it up in your browser.  If you get a blank white screen, everything is OK.</p>
<h3>Possible Errors</h3>
<p>Some possible errors you may get are&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">Unknown database 'product1_db'</pre></div></div>

<p>This will be because $db_name is wrong.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'loc1alhost' (11001) in D:\xampp\htdocs\product\db_config.php on line 3
Unknown MySQL server host 'loc1alhost' (11001)</pre></div></div>

<p>This is because the $db_host is wrong.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ro1ot'@'localhost' (using password: YES) in D:\xampp\htdocs\product\db_config.php on line 3
Access denied for user 'ro1ot'@'localhost' (using password: YES)</pre></div></div>

<p>This could be because $db_user is wrong or $db_pass is wrong.</p>
<h2>Inserting new products in to the database</h2>
<p>Create a new file and call it index.php and put it in the same location as the db_config.php file and paste the following code in it:</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: #0000ff;">'db_config.php'</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Previewing the page should result in a blank white page. This means that everything is OK.</p>
<p>Now we will create a function which will used for all our modifying database interactions such as inserting data, updating data and deleting data.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> db_action<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'insert'</span><span style="color: #339933;">:</span>
			<span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'data'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$keys</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$key</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$values</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</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;">$value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$keys</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$values</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'table'</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;">$keys</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;) VALUES (&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$values</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'update'</span><span style="color: #339933;">:</span>
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'table'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; SET &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$values</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; WHERE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; = &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'delete'</span><span style="color: #339933;">:</span>
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DELETE FROM &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'table'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; WHERE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; = &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is set up for inserting data only at the moment, both update and delete would fail at the moment, unless the data was passed on properly.</p>
<p>To insert data into the database we will pass all the information the db_function needs in an array like the one below.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'insert'</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'table'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'products'</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'data'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Product Name'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'weight'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'12.5'</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>By looking at the db_action function you can see that the action part of the array defines what we want to do in the database (insert, update or delete), then we have the table name (products, companies, ownership) and a data array which is in the format of the key (column name in the database) and the value we want to put in to the database.</p>
<p>We draw this data out the array in to a workable format using the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'data'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$keys</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$key</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$values</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</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;">$value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This goes through the data array within our main array and spits out the $keys and $values that we will use for the database.</p>
<p>Once we have the $keys and $values arrays we need to organise these in a way that MySQL will know to insert correctly.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$keys</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$values</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This sets the arrays in to strings with each field separated with a comma.  Perfect for MySQL.</p>
<p>We then insert the data in to the database using the following code.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'table'</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;">$keys</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;) VALUES (&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$values</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>From the above array, the information sent to MySQL would be:</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">INSERT</span> <span style="color: #990099; font-weight: bold;">INTO</span> products <span style="color: #FF00FF;">&#40;</span>name<span style="color: #000033;">,</span> weight<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">VALUES</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'Product Name'</span><span style="color: #000033;">,</span> <span style="color: #008000;">'12.5'</span><span style="color: #FF00FF;">&#41;</span></pre></div></div>

<h2>Inserting new companies in to the database</h2>
<p>By changing the array we can completely change the data that is going in to the database.  Now lets modify the array to insert a new company.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'insert'</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'table'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'companies'</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'data'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Something Enterprise'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'email'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'info@somethingenterprise.com'</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So with the following code, by viewing the page we will insert data in to both tables.</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: #0000ff;">'db_config.php'</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$action</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span> ? <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pid'</span><span style="color: #009900;">&#93;</span> ? <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pid'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pid'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$cid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cid'</span><span style="color: #009900;">&#93;</span> ? <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cid'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cid'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> db_action<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'insert'</span><span style="color: #339933;">:</span>
			<span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'data'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$keys</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$key</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$values</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</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;">$value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$keys</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$values</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'table'</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;">$keys</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;) VALUES (&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$values</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'update'</span><span style="color: #339933;">:</span>
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'table'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; SET &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$values</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; WHERE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; = &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'delete'</span><span style="color: #339933;">:</span>
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DELETE FROM &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'table'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; WHERE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; = &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$product</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'insert'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'table'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'products'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'data'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Product Name'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'weight'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'12.5'</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$company</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'insert'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'table'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'companies'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'data'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Something Enterprise'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'email'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'info@somethingenterprise.com'</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
db_action<span style="color: #009900;">&#40;</span><span style="color: #000088;">$product</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
db_action<span style="color: #009900;">&#40;</span><span style="color: #000088;">$company</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h2>Inserting new ownership in to the database</h2>
<p>Now that we have both a company and a product we can try linking them together. Although we will automate this later, check your database, both the product and company should have an ID of 1.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ownership</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'insert'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'table'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ownership'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'data'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'pid'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'cid'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Then by running</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">db_action<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ownership</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>  We have the entry added to the ownership table.</p>
<h2>Updating existing data</h2>
<p>To update data we just need to modify our function a little to get the data in the right format and we can update with ease.</p>
<p>To do this we update the &#8216;update&#8217; case in our switch statement to the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'update'</span><span style="color: #339933;">:</span>
			<span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'data'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">' = &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000088;">$values</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' , '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$items</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'key'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'table'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; SET &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$values</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; WHERE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; = &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span></pre></div></div>

<p>We are using a similar foreach statement but have changed the 2 arrays into 1 array as the SQL format for UPDATE is different to INSERT.</p>
<p>For the update statement to work we need to pass on the values for the WHERE statement. After a minor change to our array we have the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$updateproduct</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'update'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'table'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'products'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'data'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'New Product Name'</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'key'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'pid'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We have changed the action and added 2 new array keys, 1 called key which is the column name that we will use in our SQL statement and the id which is the cid or pid that needs to be updated.</p>
<h2>Deleting data</h2>
<p>The DELETE case in our function is even easier than our UPDATE as we don&#8217;t need to much around with any data.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'delete'</span><span style="color: #339933;">:</span>
			<span style="color: #000088;">$key</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'key'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DELETE FROM &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'table'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; WHERE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; = &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span></pre></div></div>

<p>Our DELETE array is almost identical to our UPDATE array.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$deleteproduct</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'delete'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'table'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'products'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'key'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'pid'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>All we need is the key and id as no data is needed to delete a row.</p>
<p>In part 2 we will create the HTML to do our functions.</p>
]]></content:encoded>
			<wfw:commentRss>http://jamestombs.co.uk/2008-10-12/php-mysql-making-a-basic-product-database-part-1/705/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Postal The Movie UK DVD Release Date Confirmed</title>
		<link>http://jamestombs.co.uk/2008-08-06/postal-the-movie-uk-dvd-release-date-confirmed/549</link>
		<comments>http://jamestombs.co.uk/2008-08-06/postal-the-movie-uk-dvd-release-date-confirmed/549#comments</comments>
		<pubDate>Wed, 06 Aug 2008 16:49:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[be]]></category>
		<category><![CDATA[dvd]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[frustrations]]></category>
		<category><![CDATA[postal the movie]]></category>
		<category><![CDATA[uk dvd release date]]></category>
		<category><![CDATA[usa release]]></category>

		<guid isPermaLink="false">http://www.p4th3t1c.co.uk/?p=593</guid>
		<description><![CDATA[After my initial frustrations with the Postal DVD release.  I got an email from Play about Postal being changed to preorder.  It looks like they finally have a release date of 27th October 2008, a month after the USA release.
]]></description>
			<content:encoded><![CDATA[<p>After my initial frustrations with the <a href="http://jamestombs.co.uk/2008-06-28/postal-the-movie-dvd-release-date/552">Postal DVD release</a>.  I got an email from Play about Postal being changed to preorder.  It looks like they finally have a release date of 27th October 2008, a month after the USA release.</p>
]]></content:encoded>
			<wfw:commentRss>http://jamestombs.co.uk/2008-08-06/postal-the-movie-uk-dvd-release-date-confirmed/549/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
