<?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>Linux, MySQL, PhP, Perl... &#187; Others</title>
	<atom:link href="http://linux.bgsnow.com/category/others/feed" rel="self" type="application/rss+xml" />
	<link>http://linux.bgsnow.com</link>
	<description></description>
	<lastBuildDate>Fri, 18 Jun 2010 16:30:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Shopping Cart in PHP</title>
		<link>http://linux.bgsnow.com/shopping-cart-in-php.php</link>
		<comments>http://linux.bgsnow.com/shopping-cart-in-php.php#comments</comments>
		<pubDate>Thu, 13 May 2010 17:21:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Others]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[shopping cart]]></category>

		<guid isPermaLink="false">http://linux.bgsnow.com/?p=223</guid>
		<description><![CDATA[Here is part of my shopping cart project which I created during my PHP / MySQL studies. Needless to say it is good only for studying purposes because it is insecure and quite immature: The funniest thing is that one of the requirements for this cart was to be in just 2 files. So because [...]]]></description>
			<content:encoded><![CDATA[<p>Here is part of my shopping cart project which I created during my PHP / MySQL studies. Needless to say it is good only for studying purposes because it is insecure and quite immature:</p>
<p>The funniest thing is that one of the requirements for this cart was to be in just 2 files. So because I couldn't imagine to fit it in two files I just fitted it in 2 <img src='http://linux.bgsnow.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Let the fun begin:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">go back to the store and begin shopping <span style="color: #339933;">:</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">';
&nbsp;
// If post input with '</span><span style="color: #b1b100;">do</span><span style="color: #0000ff;">' values is coming from the admin area forms we will process it here. This is because we have to use get otherwise the URL will become too long especially when we specify long description for products.
&nbsp;
switch ($_POST['</span><span style="color: #b1b100;">do</span><span style="color: #0000ff;">']) { 
&nbsp;
	case '</span>insert<span style="color: #0000ff;">':
		$command = &quot;insert into shop_products (prouct_name, price, product_image, description) values('</span><span style="color: #0000ff;">&quot;.addslashes(<span style="color: #006699; font-weight: bold;">$_POST</span>['product_name']).&quot;</span><span style="color: #0000ff;">','</span><span style="color: #0000ff;">&quot;.addslashes(<span style="color: #006699; font-weight: bold;">$_POST</span>['price']).&quot;</span><span style="color: #0000ff;">','</span><span style="color: #0000ff;">&quot;.addslashes(<span style="color: #006699; font-weight: bold;">$_POST</span>['product_image']).&quot;</span><span style="color: #0000ff;">','</span><span style="color: #0000ff;">&quot;.addslashes(<span style="color: #006699; font-weight: bold;">$_POST</span>['description']).&quot;</span><span style="color: #0000ff;">');&quot;;
		$result = mysql_query($command);
		print &quot;Data was successfully entered.
&quot;;
		mysql_close($db);
		exit();
		break;
&nbsp;
	case '</span>update<span style="color: #0000ff;">':
		$command = &quot;update shop_products set prouct_name='</span><span style="color: #0000ff;">&quot;.addslashes(<span style="color: #006699; font-weight: bold;">$_POST</span>['product_name']).&quot;</span><span style="color: #0000ff;">', price='</span><span style="color: #0000ff;">&quot;.addslashes(<span style="color: #006699; font-weight: bold;">$_POST</span>['price']).&quot;</span><span style="color: #0000ff;">', product_image='</span><span style="color: #0000ff;">&quot;.addslashes(<span style="color: #006699; font-weight: bold;">$_POST</span>['product_image']).&quot;</span><span style="color: #0000ff;">', description='</span><span style="color: #0000ff;">&quot;.addslashes(<span style="color: #006699; font-weight: bold;">$_POST</span>['description']).&quot;</span><span style="color: #0000ff;">' where product_id='</span><span style="color: #0000ff;">&quot;.<span style="color: #006699; font-weight: bold;">$_POST</span>['product'].&quot;</span><span style="color: #0000ff;">';&quot;;
		$result = mysql_query($command);
		print &quot;Data was successfully updated.
&quot;;
		mysql_close($db);
		exit();
		break;
}
&nbsp;
//Since we are limited to the number of pages we will use switch to simulate all the pages we want :)
&lt;span id=&quot;more-223&quot;&gt;&lt;/span&gt;
switch ($_GET['</span>page<span style="color: #0000ff;">']) {
&nbsp;
/* #################################################
 * #                  Checkout                     #
 * ################################################# */
&nbsp;
//Our checkout page
    case '</span>checkout<span style="color: #0000ff;">':
        if (!$_SESSION['</span>logged<span style="color: #0000ff;">']) {
&nbsp;
	echo '</span>Attention<span style="color: #339933;">:</span> You have to be registered and logged in in order to check out<span style="color: #339933;">.</span>
&nbsp;
<span style="color: #0000ff;">';
	echo &quot;Please &lt;a href=&quot;index.php?page=registration_form&quot;&gt; register &lt;/a&gt; or &lt;a href=&quot;index.php?page=login&quot;&gt;log in&lt;/a&gt; first.&quot;;
	exit();
}
&nbsp;
if ($_SESSION['</span>cart<span style="color: #0000ff;">']) {
&nbsp;
//this is the total price
$total = 0;
&nbsp;
function subtotal($price,$quantity) {
	$subtotal = ($price*$quantity) + ($price*$quantity*$tax); //multiplied by quantity and tax
	return $subtotal;
	}
&nbsp;
echo &quot;Your cart contains:&quot;;
&nbsp;
$purchase = '</span><span style="color: #0000ff;">';
&nbsp;
while (list($key, $value) = each($_SESSION['</span>cart<span style="color: #0000ff;">'])) {
&nbsp;
	//Get the price of each product
	$products_query = mysql_query(&quot;select product_id,price from shop_products where prouct_name = '</span><span style="color: #000088;">$key</span><span style="color: #0000ff;">';&quot;);
	$products = mysql_fetch_object($products_query);
&nbsp;
    echo &quot;
 $value pounds $key at the price $&quot;.$products-&amp;gt;price.&quot;.&quot;;
    $subtotal = subtotal($products-&amp;gt;price,$value);
    echo &quot; Subtotal: $ $subtotal&quot;;
    $total += $subtotal;
&nbsp;
    //Here we will insert it into the database
    $command = &quot;insert into shop_purchases (date, user_id, product_id, quantity) values(curdate(),&quot;.$_SESSION['</span>user_id<span style="color: #0000ff;">'].&quot;,$products-&amp;gt;product_id,'</span><span style="color: #000088;">$value</span><span style="color: #0000ff;">');&quot;;
	$result = mysql_query($command);
&nbsp;
    //We will also add a description for the paypal purchase
    $purchase .= $key.'</span> x <span style="color: #0000ff;">'.$value;
    $purchase .= '</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #0000ff;">';
&nbsp;
}
&nbsp;
$tax=0.08;
$total += $total*$tax;
echo '</span>
&nbsp;
Total with TAX<span style="color: #339933;">:</span> $<span style="color: #0000ff;">'.$total;
echo '</span>
Purchase recorded in the database<span style="color: #339933;">.</span> Please proceed with the payment<span style="color: #0000ff;">';
&nbsp;
//We will just add the email for the customer in case he pays with different paypal account
//All the time we have used the email as indicator for the user being logged in
//After that we can look up the address for that email from shadow.php
$purchase .= '</span>customer <span style="color: #339933;">=</span> <span style="color: #0000ff;">'.$_SESSION['</span>logged<span style="color: #0000ff;">'];
&nbsp;
//At this time only PayPal checkout is available
echo &quot;
&nbsp;
Check out with Paypal:&quot;;
&nbsp;
echo &amp;lt;&amp;lt;
&lt;form action=&quot;https://www.paypal.com/cgi-bin/webscr&quot; method=&quot;post&quot;&gt;
&lt;input name=&quot;cmd&quot; type=&quot;hidden&quot; value=&quot;_xclick&quot; /&gt;
&lt;input name=&quot;business&quot; type=&quot;hidden&quot; value=&quot;pi4a@pi4a.com&quot; /&gt;
&lt;input name=&quot;item_name&quot; type=&quot;hidden&quot; value=&quot;$purchase&quot; /&gt;
&lt;input name=&quot;item_number&quot; type=&quot;hidden&quot; /&gt;
&lt;input name=&quot;amount&quot; type=&quot;hidden&quot; value=&quot;$total&quot; /&gt;
&lt;input name=&quot;no_note&quot; type=&quot;hidden&quot; value=&quot;1&quot; /&gt;
&lt;input name=&quot;currency_code&quot; type=&quot;hidden&quot; value=&quot;USD&quot; /&gt;
&lt;input name=&quot;bn&quot; type=&quot;hidden&quot; value=&quot;PP-BuyNowBF&quot; /&gt;
&lt;input alt=&quot;Make payments with PayPal - it'</span>s fast<span style="color: #339933;">,</span> free and secure<span style="color: #339933;">!</span><span style="color: #0000ff;">&quot; name=&quot;</span>submit<span style="color: #0000ff;">&quot; src=&quot;</span>https<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//www.paypal.com/en_US/i/btn/x-click-but23.gif&quot; type=&quot;image&quot; /&gt;</span>
<span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span>
&nbsp;
PAYPAL<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;">'Your cart is empty so there is nothing to check out.'</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$begin_shopping</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* #################################################
 * #                  Logout                       #
 * ################################################# */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// A simple log out function</span>
&nbsp;
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'logout'</span><span style="color: #339933;">:</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'You are now logged out'</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'logged'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'admin'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* #################################################
 * #                  View cart                    #
 * ################################################# */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Our cart</span>
&nbsp;
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'cart'</span><span style="color: #339933;">:</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//The standard extract to remove $_GET from the Get variables</span>
<span style="color: #666666; font-style: italic;">//I have not used it for all scripts because it will be too obfuscating at times</span>
<span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #339933;">,</span> EXTR_PREFIX_SAME<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;get&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//2 functions to cut off code</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// this function will show what the cart contains</span>
<span style="color: #000000; font-weight: bold;">function</span> cart_contains<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Your cart contains now:
&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">each</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cart'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' pound(s)
'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> add_to_cart<span style="color: #009900;">&#40;</span><span style="color: #000088;">$product</span><span style="color: #339933;">,</span><span style="color: #000088;">$pounds</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cart'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$product</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$pounds</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;You have added <span style="color: #006699; font-weight: bold;">$pounds</span> pounds <span style="color: #006699; font-weight: bold;">$product</span> to your cart.
&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">return</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cart'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//we define 4 cases depending on the availability of sessions and product variables</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cart'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$product</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Your cart is empty.'</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$begin_shopping</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cart'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$product</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cart'</span><span style="color: #009900;">&#93;</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>
	add_to_cart<span style="color: #009900;">&#40;</span><span style="color: #000088;">$product</span><span style="color: #339933;">,</span><span style="color: #000088;">$pounds</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	cart_contains<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: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cart'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$product</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	cart_contains<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: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	add_to_cart<span style="color: #009900;">&#40;</span><span style="color: #000088;">$product</span><span style="color: #339933;">,</span><span style="color: #000088;">$pounds</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	cart_contains<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: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* #################################################
 * #                  Login                        #
 * ################################################# */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// A login page</span>
&nbsp;
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'login'</span><span style="color: #339933;">:</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'logged'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'You are logged in with email: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'logged'</span><span style="color: #009900;">&#93;</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> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'logged'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//We will have to use GET even for the login page in order to set page=login with a hidden value later</span>
<span style="color: #666666; font-style: italic;">//I know it is very insecure and POST should be used instead</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;</span>form<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;page&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hidden&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;login&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>table<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tbody<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td align<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;left&quot;</span><span style="color: #339933;">&gt;</span>
Email<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;email&quot;</span> size<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;25&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td align<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;left&quot;</span><span style="color: #339933;">&gt;</span>
Pass<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;password&quot;</span> size<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;25&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;password&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td align<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;left&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SUBMIT&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tbody<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span>
FORM<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: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #339933;">,</span> EXTR_PREFIX_SAME<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;get&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$users</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select user_id, email, password from shop_users where email = '<span style="color: #006699; font-weight: bold;">$email</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$users</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//First I make sure there is a $_GET['email']. Otherwise there is a bug which validates emtpy logins.</span>
<span style="color: #666666; font-style: italic;">//Then I compare for equality the two strings for email and password</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #000088;">$email</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$data</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>email <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #000088;">$password</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$data</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>password<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;You have successfully logged in.&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'logged'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span> <span style="color: #000088;">$email</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user_id'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>user_id<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//A check to see if the logged in user is admin</span>
<span style="color: #666666; font-style: italic;">//The admin is the user with user_id = 1. This makes sense because the first user to register should be the admin.</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>user_id <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'admin'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
 	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;You are an admin user. Please refresh to see the admin menu&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</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: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">//If it reaches this point die with an error</span>
<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Incorrect login!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* #################################################
 * #                Registration                   #
 * ################################################# */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Registration form </span>
&nbsp;
        <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'registration_form'</span><span style="color: #339933;">:</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;</span>table<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tbody<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td colspan<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;2&quot;</span> align<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;left&quot;</span><span style="color: #339933;">&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td align<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;right&quot;</span><span style="color: #339933;">&gt;</span>
Name<span style="color: #339933;">:&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;name&quot;</span> size<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;25&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&amp;lt;? echo <span style="color: #006699; font-weight: bold;">$_GET</span>['name']; ?&amp;gt;&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td align<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;right&quot;</span><span style="color: #339933;">&gt;</span>
Email<span style="color: #339933;">:&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td align<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;left&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;email&quot;</span> size<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;25&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&amp;lt;? echo <span style="color: #006699; font-weight: bold;">$_GET</span>['email']; ?&amp;gt;&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td align<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;right&quot;</span><span style="color: #339933;">&gt;</span>
Address<span style="color: #339933;">:&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td align<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;left&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;address&quot;</span> size<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;25&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&amp;lt;? echo <span style="color: #006699; font-weight: bold;">$_GET</span>['address']; ?&amp;gt;&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td colspan<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;2&quot;</span> align<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;left&quot;</span><span style="color: #339933;">&gt;</span>
How did you hear about us?
<span style="color: #339933;">&lt;</span>ul<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;found&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;radio&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;wordofmouth&quot;</span> <span style="color: #339933;">/&gt;</span>Word of Mouth
&nbsp;
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;found&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;radio&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;search&quot;</span> <span style="color: #339933;">/&gt;</span>Online Search
&nbsp;
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;found&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;radio&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;article&quot;</span> <span style="color: #339933;">/&gt;</span>Printed publication<span style="color: #339933;">/</span>article
&nbsp;
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;found&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;radio&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;other&quot;</span> <span style="color: #339933;">/&gt;</span>Other<span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td colspan<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;2&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input checked<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checked&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;spam&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> <span style="color: #339933;">/&gt;</span>Please email me all kinds of stuff<span style="color: #339933;">.&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td colspan<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;2&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tos&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> <span style="color: #339933;">/&gt;</span>I have read and accept Terms of service<span style="color: #339933;">.&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td colspan<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;2&quot;</span> align<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;center&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;SUBMIT&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tbody<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>table<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tbody<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span>Product name<span style="color: #339933;">:&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;product_name&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span>Price<span style="color: #339933;">:&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;price&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span>Image URL<span style="color: #339933;">:&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;product_image&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span>Description<span style="color: #339933;">:&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>textarea cols<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;40&quot;</span> rows<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;6&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;description&quot;</span><span style="color: #339933;">&gt;&lt;/</span>textarea<span style="color: #339933;">&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tbody<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;do&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hidden&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;insert&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> <span style="color: #339933;">/&gt;</span>
&nbsp;
ADD_PRODUCT_FORM<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>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</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: #0000ff;">'delete'</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'product'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000088;">$product_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'product'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;delete from shop_products where product_id = '<span style="color: #006699; font-weight: bold;">$product_id</span>' limit 1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">exit</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Selected product deleted from cart&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</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: #0000ff;">'modify'</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'product'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Here is the page for the modification of product</span>
<span style="color: #000088;">$query</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;select prouct_name, price, product_image, description from shop_products where product_id='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'product'</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;">$modify</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;">$modification</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$modify</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$product</span><span style="color: #339933;">=</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'product'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;&lt;</span>form action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;index.php&quot;</span> method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>table<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tbody<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span>Product name<span style="color: #339933;">:&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;product_name&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$modification</span>-&amp;gt;prouct_name&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span>Price<span style="color: #339933;">:&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;price&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$modification</span>-&amp;gt;price&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span>Image URL<span style="color: #339933;">:&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;product_image&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$modification</span>-&amp;gt;product_image&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span>Description<span style="color: #339933;">:&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>textarea cols<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;40&quot;</span> rows<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;6&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;description&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000088;">$modification</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>description<span style="color: #339933;">&lt;/</span>textarea<span style="color: #339933;">&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tbody<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;do&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hidden&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;update&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;product&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hidden&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$product</span>&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span>
&nbsp;
MODIFY_PRODUCT_FORM<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>
<span style="color: #666666; font-style: italic;">//This is the default sub-case when we get all the products listed</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
&nbsp;
&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<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: #0000ff;">'select * from shop_products'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_object</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>
    <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;
&nbsp;
<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
&lt;table border=&quot;</span><span style="color: #cc66cc;">1</span><span style="color: #0000ff;">&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;th&gt;product name&lt;/th&gt;
&lt;th&gt;price&lt;/th&gt;
&lt;th&gt;image_url&lt;/th&gt;
&lt;th&gt;description&lt;/th&gt;
&lt;th&gt;modify&lt;/th&gt;
&lt;th&gt;delete&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>prouct_name<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/td&gt;
&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>price<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/td&gt;
&lt;td&gt;&quot;</span><span style="color: #339933;">.</span> <span style="color: #000088;">$data</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>product_image<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/td&gt;
&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>description<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/td&gt;
&lt;td&gt; &lt;a href=&quot;</span>index<span style="color: #339933;">.</span>php?page<span style="color: #339933;">=</span>admin<span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>action<span style="color: #339933;">=</span>modify<span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>product<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&gt;product_id.&quot;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>V<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;index.php?page=admin&amp;amp;action=delete&amp;amp;product=&quot;</span><span style="color: #339933;">&gt;</span>product_id<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;gt;X&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href=&quot;</span>index<span style="color: #339933;">.</span>php?page<span style="color: #339933;">=</span>admin<span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>action<span style="color: #339933;">=</span>add_product<span style="color: #0000ff;">&quot;&gt;Add a new product&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: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Sorry. No access'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* #################################################
 * #   Admin Page - View customers                 #
 * ################################################# */</span>    
&nbsp;
        <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'view_customers'</span><span style="color: #339933;">:</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//a check to make sure this is admin</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'admin'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Customers
&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
&nbsp;
&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<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: #0000ff;">'select * from shop_users'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_object</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>
    <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;
&nbsp;
<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
&lt;table border=&quot;</span><span style="color: #cc66cc;">1</span><span style="color: #0000ff;">&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;th&gt;email&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;th&gt;password&lt;/th&gt;
&lt;th&gt;reference&lt;/th&gt;
&lt;th&gt;address&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>email<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/td&gt;
&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>name<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/td&gt;
&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>password<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/td&gt;
&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>reference<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/td&gt;
&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>address<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&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: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Sorry. No access'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* #################################################
 * #   Admin Page - View purchases                 #
 * ################################################# */</span>    
&nbsp;
        <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'view_purchases'</span><span style="color: #339933;">:</span>
<span style="color: #666666; font-style: italic;">//a check to make sure this is admin</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'admin'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Purchases
&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
&nbsp;
&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<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: #0000ff;">&quot;select sp.date, group_concat(concat(spr.prouct_name,' ', sp.quantity, ' pounds') separator ', ') as purchases, su.name from (shop_purchases as sp left join shop_users as su on sp.user_id = su.user_id) left join shop_products as spr on sp.product_id=spr.product_id group by name;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_object</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>
    <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;
&nbsp;
<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
&lt;table border=&quot;</span><span style="color: #cc66cc;">1</span><span style="color: #0000ff;">&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;th&gt;date&lt;/th&gt;
&lt;th&gt;purchases&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>date<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/td&gt;
&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>purchases<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/td&gt;
&lt;td&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>name<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&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: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Sorry. No access'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>       
&nbsp;
<span style="color: #666666; font-style: italic;">/* #################################################
 * #                  Default Index                #
 * ################################################# */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//The default index</span>
&nbsp;
        <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&lt;h2&gt;Our hot offers include:&lt;/h2&gt;
'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$products</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select * from shop_products&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$products</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&nbsp;
'</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
&nbsp;
FORM;
}
&nbsp;
echo '</span>
<span style="color: #339933;">&lt;</span>table<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tbody<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;'.<span style="color: #006699; font-weight: bold;">$data</span>-&amp;gt;product_image.'&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">/&gt;</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span><span style="color: #0000ff;">'.&quot;$data-&amp;gt;prouct_name - &quot;.$data-&amp;gt;description;
    echo &quot;
&nbsp;
&quot;.&quot;Price: $&quot;.$data-&amp;gt;price.'</span> per pound<span style="color: #0000ff;">';
&nbsp;
//In the form I will add a hidden value page = cart so that it goes to the cart case
&nbsp;
echo &amp;lt;&amp;lt;
&lt;form&gt;
Pounds: &lt;input maxlength=&quot;3&quot; name=&quot;pounds&quot; size=&quot;2&quot; type=&quot;text&quot; value=&quot;1&quot; /&gt;
&lt;input name=&quot;product&quot; type=&quot;hidden&quot; value=&quot;$data-&amp;gt;prouct_name&quot; /&gt;
&lt;input name=&quot;page&quot; type=&quot;hidden&quot; value=&quot;cart&quot; /&gt;
&lt;input type=&quot;submit&quot; value=&quot;Get&quot; /&gt;
&lt;/form&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
'</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: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://linux.bgsnow.com/shopping-cart-in-php.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Starting MySQL. ERROR! Manager of pid-file quit without updating file.</title>
		<link>http://linux.bgsnow.com/starting-mysql-error-manager-of-pid-file-quit-without-updating-file.php</link>
		<comments>http://linux.bgsnow.com/starting-mysql-error-manager-of-pid-file-quit-without-updating-file.php#comments</comments>
		<pubDate>Sat, 14 Nov 2009 21:11:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Others]]></category>
		<category><![CDATA[/var/lib/mysql]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[pid-file]]></category>

		<guid isPermaLink="false">http://linux.bgsnow.com/?p=195</guid>
		<description><![CDATA[I got that nasty error after moving around different directories in /var/lib/mysql: root@server:/var/lib/mysql# /etc/init.d/mysql start Starting MySQL. ERROR! Manager of pid-file quit without updating file. There were all kind of suggestions about it on the net, most of which had something to do with incorrect shutdown or incorrect permissions for the pid file. One of [...]]]></description>
			<content:encoded><![CDATA[<p>I got that nasty error after moving around different directories in /var/lib/mysql:</p>
<p><span style="color: #808080;">root@server:/var/lib/mysql# /etc/init.d/mysql start</span></p>
<p><span style="color: #808080;">Starting MySQL. ERROR! Manager of pid-file quit without updating file.</span></p>
<p>There were all kind of suggestions about it on the net, most of which had something to do with incorrect shutdown or incorrect permissions for the pid file.</p>
<p>One of the suggestions reminded me to read the mysql error log <img src='http://linux.bgsnow.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Here is what the error log said:</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# /etc/init.d/mysql start</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Starting MySQL. ERROR! Manager of pid-file quit without updating file.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# mysql</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">mysql                       mysql_config                mysqldumpslow               mysql_idle_processes.pm     mysqlshow                   mysql_tzinfo_to_sql</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">mysqlaccess                 mysql_convert_table_format  mysql_explain_log           mysqlimport                 mysql_sock.pm               mysql_upgrade</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">mysqladmin                  mysqld                      mysql_find_rows             mysql_install_db            mysql_tableinfo             mysql_upgrade_shell</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">mysqlbinlog                 mysqld-debug                mysql_fix_extensions        mysql_logs.sh               mysqltest                   mysql_waitpid</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">mysqlbug                    mysqld_multi                mysql_fix_privilege_tables  mysqlmanager                mysqltestmanager            mysql_zap</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">mysqlcheck                  mysqld_safe                 mysqlhotcopy                mysql_secure_installation   mysqltestmanagerc</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">mysql_client_test           mysqldump                   mysqlhotcopy.orig           mysql_setpermission         mysqltestmanager-pwgen</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# mysqld</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">mysqld         mysqld-debug   mysqld_multi   mysqld_safe    mysqldump      mysqldumpslow</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# mysqld</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">mysqld         mysqld-debug   mysqld_multi   mysqld_safe    mysqldump      mysqldumpslow</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# mysqld_safe start</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Starting mysqld daemon with databases from /var/lib/mysql</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">STOPPING server from pid file /var/lib/mysql/host.server.bgsnow.com.pid</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">091114 13:14:56  mysqld ended</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# ll /var/lib/mysql/host.server.bgsnow.com.p</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# touch /var/lib/mysql/host.server.bgsnow.com.pid</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# chown mysql: /var/lib/mysql/host.server.bgsnow.com.pid</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# /etc/init.d/mysql start</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Starting MySQL. ERROR! Manager of pid-file quit without updating file.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# tail -f /var/lib/mysql</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">mysql/    mysqlA/   mysqlOLD/</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# tail -f /var/lib/mysql/mysql-slow.log</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">host.server.bgsnow.com.err  ib_logfile0                mysql-slow.log             optistr2_optistreams/</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">ibdata1                    ib_logfile1                optistr2_opti/             optistr2_perldesk/</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# tail -f /var/lib/mysql/host.server.bgsnow.com.err</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">InnoDB: Restoring possible half-written data pages from the doublewrite</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">InnoDB: buffer...</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">InnoDB: Doing recovery: scanned up to log sequence number 0 43655</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">091114 13:16:20  InnoDB: Starting an apply batch of log records to the database...</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">InnoDB: Progress in percents: 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">InnoDB: Apply batch completed</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">091114 13:16:21  InnoDB: Started; log sequence number 0 43655</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">091114 13:16:21 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">091114 13:16:21  mysqld ended</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">091114 13:16:52  mysqld started</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">InnoDB: Log scan progressed past the checkpoint lsn 0 36808</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">091114 13:16:52  InnoDB: Database was not shut down normally!</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">InnoDB: Starting crash recovery.</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">InnoDB: Reading tablespace information from the .ibd files...</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">InnoDB: Restoring possible half-written data pages from the doublewrite</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">InnoDB: buffer...</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">InnoDB: Doing recovery: scanned up to log sequence number 0 43655</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">091114 13:16:52  InnoDB: Starting an apply batch of log records to the database...</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">InnoDB: Progress in percents: 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">InnoDB: Apply batch completed</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">091114 13:16:53  InnoDB: Started; log sequence number 0 43655</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">091114 13:16:53 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">091114 13:16:53  mysqld ended</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# ls</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">./  ../  host.server.bgsnow.com.err  ibdata1  ib_logfile0  ib_logfile1  mysql-slow.log  optistr2_opti/  optistr2_optistreams/  optistr2_perldesk/</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# ll ../</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">alternatives/     dhclient/         logrotate.status  mlocate/          mysqlA/           pgsql/            rkhunter/         sepolgen/         stateless/        yum/</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">dbus/             games/            misc/             mysql/            mysqlOLD/         random-seed       rpm/              spamassassin/     texmf/</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# ll ../</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">alternatives/     dhclient/         logrotate.status  mlocate/          mysqlA/           pgsql/            rkhunter/         sepolgen/         stateless/        yum/</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">dbus/             games/            misc/             mysql/            mysqlOLD/         random-seed       rpm/              spamassassin/     texmf/</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# ll ../mysqlOLD/</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">cphulkd/                   host.server.bgsnow.com.err  ib_logfile0                mysql/                     roundcube/                 sentry_stat/</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">eximstats/                 host.server.bgsnow.com.pid  ib_logfile1                mysql-slow.log             sentry/                    sentry_traf/</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">horde/                     ibdata1                    leechprotect/              mysql.sock                 sentry_mambo/              test/</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# ll ../mysqlOLD/*</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# ls</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">./  ../  host.server.bgsnow.com.err  ibdata1  ib_logfile0  ib_logfile1  mysql-slow.log  optistr2_opti/  optistr2_optistreams/  optistr2_perldesk/</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# mv ../mysqlOLD/</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">cphulkd/                   host.server.bgsnow.com.err  ib_logfile0                mysql/                     roundcube/                 sentry_stat/</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">eximstats/                 host.server.bgsnow.com.pid  ib_logfile1                mysql-slow.log             sentry/                    sentry_traf/</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">horde/                     ibdata1                    leechprotect/              mysql.sock                 sentry_mambo/              test/</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# mv ../mysqlOLD/* ./</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">mv: overwrite `./host.server.bgsnow.com.err'? y</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">mv: overwrite `./ibdata1'? n</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">mv: overwrite `./ib_logfile0'? n</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">mv: overwrite `./ib_logfile1'? n</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">mv: overwrite `./mysql-slow.log'? y</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">root@server:/var/lib/mysql# /etc/init.d/mysql restart</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Shutting down MySQL. SUCCESS!</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Starting MySQL. SUCCESS!</div>
<p><span style="color: #808080;">root@server:/var/lib/mysql# tail -f /var/lib/mysql/host.server.bgsnow.com.err </span></p>
<p><span style="color: #808080;">InnoDB: Restoring possible half-written data pages from the doublewrite</span></p>
<p><span style="color: #808080;">InnoDB: buffer...</span></p>
<p><span style="color: #808080;">InnoDB: Doing recovery: scanned up to log sequence number 0 43655</span></p>
<p><span style="color: #808080;">091114 13:16:20  InnoDB: Starting an apply batch of log records to the database...</span></p>
<p><span style="color: #808080;">InnoDB: Progress in percents: 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 </span></p>
<p><span style="color: #808080;">InnoDB: Apply batch completed</span></p>
<p><span style="color: #808080;">091114 13:16:21  InnoDB: Started; log sequence number 0 43655</span></p>
<p><span style="color: #808080;">091114 13:16:21 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist</span></p>
<p><span style="color: #808080;">091114 13:16:21  mysqld ended</span></p>
<p>Obviously I have forgotten to move back the mysql directory which is responsible for the database for all privileges, databases and so on <img src='http://linux.bgsnow.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   So moving it back along with the rest of the core files solved the problem:</p>
<p><span style="color: #808080;">root@server:/var/lib/mysql# mv ../mysqlOLD/* ./</span></p>
<p><span style="color: #808080;">mv: overwrite `./host.server.bgsnow.com.err'? y</span></p>
<p><span style="color: #808080;">mv: overwrite `./ibdata1'? n</span></p>
<p><span style="color: #808080;">mv: overwrite `./ib_logfile0'? n</span></p>
<p><span style="color: #808080;">mv: overwrite `./ib_logfile1'? n</span></p>
<p><span style="color: #808080;">mv: overwrite `./mysql-slow.log'? y</span></p>
<p><span style="color: #00ff00;">root@server:/var/lib/mysql# /etc/init.d/mysql restart</span></p>
<p><span style="color: #00ff00;">Shutting down MySQL. SUCCESS! </span></p>
<p><span style="color: #808080;"><span style="color: #00ff00;">Starting MySQL. SUCCESS!</span><span style="color: #00ff00;"> </span></span></p>
<p>Thus if you have similar problems, the first thing is to check the MySQL error log and don't believe the misleading error about the PID <img src='http://linux.bgsnow.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://linux.bgsnow.com/starting-mysql-error-manager-of-pid-file-quit-without-updating-file.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Best Joomla Modules</title>
		<link>http://linux.bgsnow.com/best-joomla-modules.php</link>
		<comments>http://linux.bgsnow.com/best-joomla-modules.php#comments</comments>
		<pubDate>Sat, 17 Oct 2009 09:35:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Others]]></category>
		<category><![CDATA[Joomla SEO component]]></category>
		<category><![CDATA[sh404SEF free]]></category>

		<guid isPermaLink="false">http://linux.bgsnow.com/?p=180</guid>
		<description><![CDATA[Joomla is my favorite Content Management System even though it is years behind WordPress functionality. Of course, WordPress is not a CMS So when I decided to build a new site using Joomla 1.5 I have had to find solutions to the following problems: 1. SEO component. Joomla SEO / SEF couldn'tt suck more... From the time [...]]]></description>
			<content:encoded><![CDATA[<p>Joomla is my favorite Content Management System even though it is years behind WordPress functionality. Of course, WordPress is not a CMS <img src='http://linux.bgsnow.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So when I decided to build a new site using Joomla 1.5 I have had to find solutions to the following problems:</p>
<p>1. SEO component. Joomla SEO / SEF couldn'tt suck more... From the time of Joomla 1.0.* I know that one of the core Joomla developers had a commercial SEO component. I guess that's why Joomla will never have elementary SEO functions like really friendly URLs. Yes, there are some in-built... but that's just bullsh*t. Of course, there are 2-3 commercial (or let's call them paid for political correctness) plugins which probably work fine.</p>
<p>Anyway, I have made my choice to<strong> sh404SEF</strong>. Next I have tried a way to get it free of charge. Luckily, I stumbed upon <a href="http://www.jaredritchey.com/sh404sef-free-download/">this site</a> offering it for free download <img src='http://linux.bgsnow.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  As a whole, it works fine even though my Joomla is quite complex. It has Joomfish and many other plugins...</p>
]]></content:encoded>
			<wfw:commentRss>http://linux.bgsnow.com/best-joomla-modules.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Toughest Spam Protection</title>
		<link>http://linux.bgsnow.com/the-toughest-spam-protection.php</link>
		<comments>http://linux.bgsnow.com/the-toughest-spam-protection.php#comments</comments>
		<pubDate>Sun, 11 Oct 2009 08:11:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Others]]></category>
		<category><![CDATA[akismet]]></category>
		<category><![CDATA[antispam]]></category>
		<category><![CDATA[project honeypot]]></category>
		<category><![CDATA[spam]]></category>
		<category><![CDATA[spam protection]]></category>

		<guid isPermaLink="false">http://linux.bgsnow.com/?p=165</guid>
		<description><![CDATA[A month ago I remembered about an old blog we have had and checked it out... After months of negligence it had 9999 spam comments It was outdated and had no spam protection at all... It was quite unpopular (no PR at all) but it has still been of interest to spammers... Still spam is [...]]]></description>
			<content:encoded><![CDATA[<p><span style="background-color: #ffffff;">A month ago I remembered about an old blog we have had and checked it out... After months of negligence it had 9999 spam comments <img src='http://linux.bgsnow.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  It was outdated and had no spam protection at all... It was quite unpopular (no PR at all) but it has still been of interest to spammers... </span></p>
<p><span style="background-color: #ffffff;">Still spam is more than most people think - it is not only about bots and there is much more than just posts about popular medical products. My experience with Spam fighting comes from a popular hosting forum with Google PR 8 and a few popular blogs (WordPress).</span></p>
<p><span style="background-color: #ffffff;">So when I really want to protect a site from spammers I follow a scenario of 3 steps:</span></p>
<p><span style="background-color: #ffffff;">1. Implement <a href="http://www.projecthoneypot.org/" target="_blank">Project HoneyPot</a>. This is the first trap for spammers - both bots and humans. Time has shown that there are many humans posting spam comments and posts. Project HoneyPot detects them all through a large distributed network of honeypots and adds them to a blocklist. </span></p>
<p><span style="background-color: #ffffff;">The project offers integration about almost any application. It has even a beta version of an Apache module so its implementation should not be hard.</span></p>
<p>2. The next thing to do is to enable <a href="http://recaptcha.net/" target="_blank">reCaptcha</a>. This way we address all threats from bots because most spam does come from bots. These bots often reside on zombie computers and might not have been spotted by Project Honeypot yet.</p>
<p>Of course reCaptcha is not perfect and some advanced bots can pass it. Its biggest drawback is that human spammers bypass it easily.</p>
<p>3. The last step is to set <a href="http://akismet.com/" target="_blank">Akismet</a>. This is the final trap, the boss of the Spam defense. It filters posts by hundreds of tests about known spam patterns. It is much advanced than the previous methods and ensures very high level of defense.</p>
<p>If you implement the above solution with all of its parts you can feel pretty safe about your site or blog. It's biggest benefit is that it saves you a lot of work and does not require you to update manually anything.</p>
<p>Still, it is a 99.99% protection. A popular site is targeted by more than 1000 spam attempts a day which means that more than 1 spam post / comment will go through.</p>
<p>That's why it is a good idea to monitor and even pre-approve each post / comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://linux.bgsnow.com/the-toughest-spam-protection.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing image preview size for attached images in PhpBB3</title>
		<link>http://linux.bgsnow.com/changing-image-preview-size-for-attached-images-in-phpbb3.php</link>
		<comments>http://linux.bgsnow.com/changing-image-preview-size-for-attached-images-in-phpbb3.php#comments</comments>
		<pubDate>Tue, 28 Oct 2008 20:22:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Others]]></category>

		<guid isPermaLink="false">http://linux.bgsnow.com/?p=110</guid>
		<description><![CDATA[Imagine having a nice PhpBB3 forum where you'd love to attach inline photos in your posts. The problem is that max height for the image size is set to 350 by default for the prosilver theme. I managed to change it only in the following way: Open your forums mysql database and find the table [...]]]></description>
			<content:encoded><![CDATA[<p>Imagine having a nice PhpBB3 forum where you'd love to attach inline photos in your posts. The problem is that max height for the image size is set to 350 by default for the prosilver theme. I managed to change it only in the following way:</p>
<p>Open your forums mysql database and find the table phpbb_<span class="item">styles_theme. There go to row </span>theme_name=prosilver, find theme_data field. There will be your whole css for the theme loaded. Find:</p>
<p>.attach-image {<br />
margin: 3px 0;<br />
width: 100%;<br />
max-height: 350px;<br />
overflow: auto;<br />
}</p>
<p>Change it to:</p>
<p>.attach-image {<br />
margin: 3px 0;<br />
width: 100%;<br />
max-height: <strong>1350px</strong>;<br />
overflow: auto;<br />
}</p>
<p>There are two things to consider:</p>
<p>1. The above is probably loaded at some time from the file styles/prosilver/theme/content.css. It is a good idea to make the same change there too.</p>
<p>2. Make sure to clear your forum's cache, i.e. delete everything inside the cache/ directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://linux.bgsnow.com/changing-image-preview-size-for-attached-images-in-phpbb3.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>cPanel mailbox to maildir problems</title>
		<link>http://linux.bgsnow.com/cpanel-mailbox-to-maildir-problems.php</link>
		<comments>http://linux.bgsnow.com/cpanel-mailbox-to-maildir-problems.php#comments</comments>
		<pubDate>Mon, 28 Jul 2008 14:19:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Others]]></category>
		<category><![CDATA[linux cpanel courier maildir mailbox exim]]></category>

		<guid isPermaLink="false">http://linux.bgsnow.com/?p=19</guid>
		<description><![CDATA[Sometimes after cPanel's maildir conversion (/scripts/convert2maildir) there might be missing mails. In my case the mails from the Sent folder were missing. Despite all of my efforts to re-run /scripts/convert2maildir with option 3 (Convert partially converted mail accounts), there was still a huge mailbox file for the Sent folder in the user's account (/home/user/mail/bgsnow.com/problem_user/Sent). Of [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes after cPanel's maildir conversion (/scripts/convert2maildir) there might be missing mails. In my case the mails from the Sent folder were missing.</p>
<p>Despite all of my efforts to re-run /scripts/convert2maildir with option 3 (Convert partially converted mail accounts), there was still a huge mailbox file for the Sent folder in the user's account (/home/user/mail/bgsnow.com/problem_user/Sent). Of course, the maildir folder .Sent (/home/user/mail/bgsnow.com/problem_user/.Sent/) did not have any of the mails from the Sent mailbox file.</p>
<p>After googling for some time and trying third party scripts to no avail, I have turned to a simple solution. I have created a directory /home/user/mail/bgsnow.com/test/. This should represent the mail directory for a fake email account test@bgsnow.com. Then I have copied the Sent file from the user which has problems (/home/user/mail/bgsnow.com/problem_user/Sent) to this directory and re-run /scripts/convert2maildir. This created the needed maildir directory .Sent (/home/user/mail/bgsnow.com/test/.Sent)  which I copied directly to the mail directory for the user with problems (/home/user/mail/bgsnow.com/problem_user/).</p>
<p>This fixed the problem for me <img src='http://linux.bgsnow.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://linux.bgsnow.com/cpanel-mailbox-to-maildir-problems.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to disable &quot;smart&quot; auto formatting in WordPress</title>
		<link>http://linux.bgsnow.com/how-to-disable-smart-auto-formatting-in-wordpress.php</link>
		<comments>http://linux.bgsnow.com/how-to-disable-smart-auto-formatting-in-wordpress.php#comments</comments>
		<pubDate>Mon, 14 Apr 2008 18:54:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Others]]></category>

		<guid isPermaLink="false">http://linux.bgsnow.com/?p=9</guid>
		<description><![CDATA[WordPress has an ugly default feature to turn " or ' into ` and all kind of crazy letters. This is somewhere ok unless you write code as in my case. Then all of your code will be unusable. Here is a simple solution to disable this smart auto formatting. Open the file wp-includes/default-filters.php and [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress has an ugly default feature to turn " or ' into ` and all kind of crazy letters. This is somewhere ok unless you write code as in my case. Then all of your code will be unusable.</p>
<p>Here is a simple solution to disable this smart auto formatting. Open the file wp-includes/default-filters.php and  comment the following line:</p>
<p>//add_filter('the_content', 'wptexturize');</p>
<p>I've searched for another more civilized solution but to no avail. Needless to say this works with any theme, any character encoding and makes no other changes to WordPress's default behavior.</p>
]]></content:encoded>
			<wfw:commentRss>http://linux.bgsnow.com/how-to-disable-smart-auto-formatting-in-wordpress.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
