<?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>Shoutbux &#124; submit your thoughts &#187; Tutorial &#8211; PHP</title>
	<atom:link href="http://www.shoutbux.com/category/tutorial-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shoutbux.com</link>
	<description>Post your thoughts about IT, business, love and relationships, food, dining and a lot more!</description>
	<lastBuildDate>Wed, 28 Jul 2010 07:04:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>PHP File Upload</title>
		<link>http://www.shoutbux.com/php-file-upload/</link>
		<comments>http://www.shoutbux.com/php-file-upload/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 06:00:58 +0000</pubDate>
		<dc:creator>zemog</dc:creator>
				<category><![CDATA[Tutorial - PHP]]></category>
		<category><![CDATA[file upload]]></category>
		<category><![CDATA[php tutorial]]></category>
		<category><![CDATA[uploading files using php]]></category>

		<guid isPermaLink="false">http://www.shoutbux.com/?p=820</guid>
		<description><![CDATA[With PHP, it is possible to upload files to the server.]]></description>
			<content:encoded><![CDATA[<p>Create an Upload-File Form</p>
<p>To allow users to upload files from a form can be very useful.</p>
<p>Look at the following HTML form for uploading files:</p>
<pre style="font-size: 1.3 em;
 	color: blue;
	margin: 10px;
	padding:10px;
	background: #FFFFB3"><code>&lt;html&gt;
&lt;body&gt;

&lt;form action="upload_file.php" method="post"
enctype="multipart/form-data"&gt;
&lt;label for="file"&gt;Filename:&lt;/label&gt;
&lt;input type="file" name="file" id="file" /&gt;
&lt;br /&gt;
&lt;input type="submit" name="submit" value="Submit" /&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt; </code></pre>
<p>Notice the following about the HTML form above:</p>
<p>    * The enctype attribute of the < form > tag specifies which content-type to use when submitting the form. &#8220;multipart/form-data&#8221; is used when a form requires binary data, like the contents of a file, to be uploaded<br />
    * The type=&#8221;file&#8221; attribute of the < input > tag specifies that the input should be processed as a file. For example, when viewed in a browser, there will be a browse-button next to the input field</p>
<p>Note: Allowing users to upload files is a big security risk. Only permit trusted users to perform file uploads.</p>
<p>Create The Upload Script</p>
<p>The &#8220;upload_file.php&#8221; file contains the code for uploading a file:</p>
<pre style="font-size: 1.3 em;
 	color: blue;
	margin: 10px;
	padding:10px;
	background: #FFFFB3"><code>&lt;?php
if ($_FILES["file"]["error"] &gt; 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "&lt;br /&gt;";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "&lt;br /&gt;";
  echo "Type: " . $_FILES["file"]["type"] . "&lt;br /&gt;";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb&lt;br /&gt;";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
  }
?&gt; </code></pre>
<p>By using the global PHP $_FILES array you can upload files from a client computer to the remote server.</p>
<p>The first parameter is the form&#8217;s input name and the second index can be either &#8220;name&#8221;, &#8220;type&#8221;, &#8220;size&#8221;, &#8220;tmp_name&#8221; or &#8220;error&#8221;. Like this:</p>
<p>    * $_FILES["file"]["name"] &#8211; the name of the uploaded file<br />
    * $_FILES["file"]["type"] &#8211; the type of the uploaded file<br />
    * $_FILES["file"]["size"] &#8211; the size in bytes of the uploaded file<br />
    * $_FILES["file"]["tmp_name"] &#8211; the name of the temporary copy of the file stored on the server<br />
    * $_FILES["file"]["error"] &#8211; the error code resulting from the file upload</p>
<p>This is a very simple way of uploading files. For security reasons, you should add restrictions on what the user is allowed to upload.</p>
<p>Restrictions on Upload</p>
<p>In this script we add some restrictions to the file upload. The user may only upload .gif or .jpeg files and the file size must be under 20 kb:</p>
<pre style="font-size: 1.3 em;
 	color: blue;
	margin: 10px;
	padding:10px;
	background: #FFFFB3"><code>&lt;?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&amp;&amp; ($_FILES["file"]["size"] &lt; 20000))
  {
  if ($_FILES["file"]["error"] &gt; 0)
    {
    echo "Error: " . $_FILES["file"]["error"] . "&lt;br /&gt;";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "&lt;br /&gt;";
    echo "Type: " . $_FILES["file"]["type"] . "&lt;br /&gt;";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb&lt;br /&gt;";
    echo "Stored in: " . $_FILES["file"]["tmp_name"];
    }
  }
else
  {
  echo "Invalid file";
  }
?&gt; </code></pre>
<p>Note: For IE to recognize jpg files the type must be pjpeg, for FireFox it must be jpeg.</p>
<p>Saving the Uploaded File</p>
<p>The examples above create a temporary copy of the uploaded files in the PHP temp folder on the server.</p>
<p>The temporary copied files disappears when the script ends. To store the uploaded file we need to copy it to a different location:</p>
<pre style="font-size: 1.3 em;
 	color: blue;
	margin: 10px;
	padding:10px;
	background: #FFFFB3"><code>&lt;?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&amp;&amp; ($_FILES["file"]["size"] &lt; 20000))
  {
  if ($_FILES["file"]["error"] &gt; 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "&lt;br /&gt;";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "&lt;br /&gt;";
    echo "Type: " . $_FILES["file"]["type"] . "&lt;br /&gt;";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb&lt;br /&gt;";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "&lt;br /&gt;";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?&gt; </code></pre>
<p>The script above checks if the file already exists, if it does not, it copies the file to the specified folder.</p>
<p>Note: This example saves the file to a new folder called &#8220;upload&#8221;</p>
<p><script type="text/javascript">// <![CDATA[
        google_ad_client = "pub-9932804508693643"; /* 468x60_shoutbux */ google_ad_slot = "0201046266"; google_ad_width = 468; google_ad_height = 60;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d820').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d820" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fwww.shoutbux.com%2Fphp-file-upload%2F&amp;submitHeadline=PHP+File+Upload&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-file-upload%2F&amp;title=PHP+File+Upload" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-file-upload%2F&amp;title=PHP+File+Upload" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.shoutbux.com%2Fphp-file-upload%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.shoutbux.com%2Fphp-file-upload%2F&amp;title=PHP+File+Upload" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-file-upload%2F&amp;bm_description=PHP+File+Upload" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.shoutbux.com%2Fphp-file-upload%2F&amp;T=PHP+File+Upload" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-file-upload%2F&amp;title=PHP+File+Upload" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-file-upload%2F&amp;title=PHP+File+Upload" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.shoutbux.com%2Fphp-file-upload%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-file-upload%2F" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+PHP+File+Upload+@+http%3A%2F%2Fwww.shoutbux.com%2Fphp-file-upload%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.shoutbux.com%2Fphp-file-upload%2F&amp;t=PHP+File+Upload" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d820').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shoutbux.com/php-file-upload/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP MySQL Create Database and Tables</title>
		<link>http://www.shoutbux.com/php-mysql-create-database-and-tables/</link>
		<comments>http://www.shoutbux.com/php-mysql-create-database-and-tables/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 02:25:34 +0000</pubDate>
		<dc:creator>zemog</dc:creator>
				<category><![CDATA[Tutorial - PHP]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql create database]]></category>
		<category><![CDATA[php tutorial]]></category>

		<guid isPermaLink="false">http://www.shoutbux.com/?p=802</guid>
		<description><![CDATA[A database holds one or multiple tables.]]></description>
			<content:encoded><![CDATA[<p>Create a Database</p>
<p>The CREATE DATABASE statement is used to create a database in MySQL.<br />
Syntax</p>
<pre style="font-size: 1.3 em;
 	color: blue;
	margin: 10px;
	padding:10px;
	background: #FFFFB3"><code>CREATE DATABASE database_name </code></pre>
<p>To learn more about SQL, please visit our SQL tutorial.</p>
<p>To get PHP to execute the statement above we must use the mysql_query() function. This function is used to send a query or command to a MySQL connection.<br />
Example</p>
<p>The following example creates a database called &#8220;my_db&#8221;:</p>
<pre style="font-size: 1.3 em;
 	color: blue;
	margin: 10px;
	padding:10px;
	background: #FFFFB3"><code>&lt;?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

if (mysql_query("CREATE DATABASE my_db",$con))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }

mysql_close($con);
?&gt; </code></pre>
<p>Create a Table</p>
<p>The CREATE TABLE statement is used to create a table in MySQL.<br />
Syntax</p>
<pre style="font-size: 1.3 em;
 	color: blue;
	margin: 10px;
	padding:10px;
	background: #FFFFB3"><code>CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
....
) </code></pre>
<p>To learn more about SQL, please visit our SQL tutorial.</p>
<p>We must add the CREATE TABLE statement to the mysql_query() function to execute the command.<br />
Example</p>
<p>The following example creates a table named &#8220;Persons&#8221;, with three columns. The column names will be &#8220;FirstName&#8221;, &#8220;LastName&#8221; and &#8220;Age&#8221;:</p>
<pre style="font-size: 1.3 em;
 	color: blue;
	margin: 10px;
	padding:10px;
	background: #FFFFB3"><code>&lt;?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// Create database
if (mysql_query("CREATE DATABASE my_db",$con))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }

// Create table
mysql_select_db("my_db", $con);
$sql = "CREATE TABLE Persons
(
FirstName varchar(15),
LastName varchar(15),
Age int
)";

// Execute query
mysql_query($sql,$con);

mysql_close($con);
?&gt; </code></pre>
<p>Important: A database must be selected before a table can be created. The database is selected with the mysql_select_db() function.</p>
<p>Note: When you create a database field of type varchar, you must specify the maximum length of the field, e.g. varchar(15).</p>
<p>The data type specifies what type of data the column can hold.</p>
<p>Primary Keys and Auto Increment Fields</p>
<p>Each table should have a primary key field.</p>
<p>A primary key is used to uniquely identify the rows in a table. Each primary key value must be unique within the table. Furthermore, the primary key field cannot be null because the database engine requires a value to locate the record.</p>
<p>The following example sets the personID field as the primary key field. The primary key field is often an ID number, and is often used with the AUTO_INCREMENT setting. AUTO_INCREMENT automatically increases the value of the field by 1 each time a new record is added. To ensure that the primary key field cannot be null, we must add the NOT NULL setting to the field.<br />
Example</p>
<pre style="font-size: 1.3 em;
 	color: blue;
	margin: 10px;
	padding:10px;
	background: #FFFFB3"><code>$sql = "CREATE TABLE Persons
(
personID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(personID),
FirstName varchar(15),
LastName varchar(15),
Age int
)";

mysql_query($sql,$con); </code></pre>
<p><script type="text/javascript">// <![CDATA[
        google_ad_client = "pub-9932804508693643"; /* 468x60_shoutbux */ google_ad_slot = "0201046266"; google_ad_width = 468; google_ad_height = 60;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d802').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d802" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fwww.shoutbux.com%2Fphp-mysql-create-database-and-tables%2F&amp;submitHeadline=PHP+MySQL+Create+Database+and+Tables&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-mysql-create-database-and-tables%2F&amp;title=PHP+MySQL+Create+Database+and+Tables" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-mysql-create-database-and-tables%2F&amp;title=PHP+MySQL+Create+Database+and+Tables" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.shoutbux.com%2Fphp-mysql-create-database-and-tables%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.shoutbux.com%2Fphp-mysql-create-database-and-tables%2F&amp;title=PHP+MySQL+Create+Database+and+Tables" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-mysql-create-database-and-tables%2F&amp;bm_description=PHP+MySQL+Create+Database+and+Tables" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.shoutbux.com%2Fphp-mysql-create-database-and-tables%2F&amp;T=PHP+MySQL+Create+Database+and+Tables" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-mysql-create-database-and-tables%2F&amp;title=PHP+MySQL+Create+Database+and+Tables" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-mysql-create-database-and-tables%2F&amp;title=PHP+MySQL+Create+Database+and+Tables" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.shoutbux.com%2Fphp-mysql-create-database-and-tables%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-mysql-create-database-and-tables%2F" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+PHP+MySQL+Create+Database+and+Tables+@+http%3A%2F%2Fwww.shoutbux.com%2Fphp-mysql-create-database-and-tables%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.shoutbux.com%2Fphp-mysql-create-database-and-tables%2F&amp;t=PHP+MySQL+Create+Database+and+Tables" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d802').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shoutbux.com/php-mysql-create-database-and-tables/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP Switch Statement</title>
		<link>http://www.shoutbux.com/php-switch-statement/</link>
		<comments>http://www.shoutbux.com/php-switch-statement/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 02:18:33 +0000</pubDate>
		<dc:creator>zemog</dc:creator>
				<category><![CDATA[Tutorial - PHP]]></category>
		<category><![CDATA[php condition]]></category>
		<category><![CDATA[php switch statement]]></category>

		<guid isPermaLink="false">http://www.shoutbux.com/?p=800</guid>
		<description><![CDATA[Conditional statements are used to perform different actions based on different conditions.]]></description>
			<content:encoded><![CDATA[<p>The PHP Switch Statement</p>
<p>Use the switch statement to select one of many blocks of code to be executed.<br />
Syntax</p>
<pre style="font-size: 1.3 em;
 	color: blue;
	margin: 10px;
	padding:10px;
	background: #FFFFB3"><code>switch (n)
{
case label1:
  code to be executed if n=label1;
  break;
case label2:
  code to be executed if n=label2;
  break;
default:
  code to be executed if n is different from both label1 and label2;
} </code></pre>
<p>This is how it works: First we have a single expression n (most often a variable), that is evaluated once. The value of the expression is then compared with the values for each case in the structure. If there is a match, the block of code associated with that case is executed. Use break to prevent the code from running into the next case automatically. The default statement is used if no match is found.<br />
Example</p>
<pre style="font-size: 1.3 em;
 	color: blue;
	margin: 10px;
	padding:10px;
	background: #FFFFB3"><code>&lt;html&gt;
&lt;body&gt;

&lt;?php
switch ($x)
{
case 1:
  echo "Number 1";
  break;
case 2:
  echo "Number 2";
  break;
case 3:
  echo "Number 3";
  break;
default:
  echo "No number between 1 and 3";
}
?&gt;

&lt;/body&gt;
&lt;/html&gt; </code></pre>
<p><script type="text/javascript">// <![CDATA[
        google_ad_client = "pub-9932804508693643"; /* 468x60_shoutbux */ google_ad_slot = "0201046266"; google_ad_width = 468; google_ad_height = 60;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d800').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d800" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fwww.shoutbux.com%2Fphp-switch-statement%2F&amp;submitHeadline=PHP+Switch+Statement&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-switch-statement%2F&amp;title=PHP+Switch+Statement" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-switch-statement%2F&amp;title=PHP+Switch+Statement" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.shoutbux.com%2Fphp-switch-statement%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.shoutbux.com%2Fphp-switch-statement%2F&amp;title=PHP+Switch+Statement" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-switch-statement%2F&amp;bm_description=PHP+Switch+Statement" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.shoutbux.com%2Fphp-switch-statement%2F&amp;T=PHP+Switch+Statement" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-switch-statement%2F&amp;title=PHP+Switch+Statement" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-switch-statement%2F&amp;title=PHP+Switch+Statement" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.shoutbux.com%2Fphp-switch-statement%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-switch-statement%2F" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+PHP+Switch+Statement+@+http%3A%2F%2Fwww.shoutbux.com%2Fphp-switch-statement%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.shoutbux.com%2Fphp-switch-statement%2F&amp;t=PHP+Switch+Statement" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d800').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shoutbux.com/php-switch-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Include File</title>
		<link>http://www.shoutbux.com/php-include-file/</link>
		<comments>http://www.shoutbux.com/php-include-file/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 02:15:22 +0000</pubDate>
		<dc:creator>zemog</dc:creator>
				<category><![CDATA[Tutorial - PHP]]></category>
		<category><![CDATA[include function]]></category>
		<category><![CDATA[php tutorial]]></category>
		<category><![CDATA[require function]]></category>
		<category><![CDATA[server side includes]]></category>

		<guid isPermaLink="false">http://www.shoutbux.com/?p=798</guid>
		<description><![CDATA[Includes are very important function of PHP that you should now.]]></description>
			<content:encoded><![CDATA[<p>Server Side Includes (SSI)</p>
<p>You can insert the content of one PHP file into another PHP file before the server executes it, with the include() or require() function.</p>
<p>The two functions are identical in every way, except how they handle errors:</p>
<p>* include() generates a warning, but the script will continue execution<br />
* require() generates a fatal error, and the script will stop</p>
<p>These two functions are used to create functions, headers, footers, or elements that will be reused on multiple pages.</p>
<p>Server side includes saves a lot of work. This means that you can create a standard header, footer, or menu file for all your web pages. When the header needs to be updated, you can only update the include file, or when you add a new page to your site, you can simply change the menu file (instead of updating the links on all your web pages).<br />
PHP include() Function</p>
<p>The include() function takes all the content in a specified file and includes it in the current file.</p>
<p>If an error occurs, the include() function generates a warning, but the script will continue execution.<br />
Example 1</p>
<p>Assume that you have a standard header file, called &#8220;header.php&#8221;. To include the header file in a page, use the include() function:</p>
<pre style="font-size: 1.3 em;   	color: blue;  	margin: 10px;  	padding:10px;  	background: #FFFFB3"><code></code>&lt;html&gt;
 &lt;body&gt;

 &lt;?php include("header.php"); ?&gt;
 &lt;h1&gt;Welcome to my home page!&lt;/h1&gt;
 &lt;p&gt;Some text.&lt;/p&gt;

 &lt;/body&gt;
 &lt;/html&gt;</pre>
<p>Example 2</p>
<p>Assume we have a standard menu file, called &#8220;menu.php&#8221;, that should be used on all pages:</p>
<pre style="font-size: 1.3 em;   	color: blue;  	margin: 10px;  	padding:10px;  	background: #FFFFB3">&lt;a href="/default.php"&gt;Home&lt;/a&gt;
 &lt;a href="/tutorials.php"&gt;Tutorials&lt;/a&gt;
 &lt;a href="/references.php"&gt;References&lt;/a&gt;
 &lt;a href="/examples.php"&gt;Examples&lt;/a&gt;
 &lt;a href="/about.php"&gt;About Us&lt;/a&gt;
 &lt;a href="/contact.php"&gt;Contact Us&lt;/a&gt;</pre>
<p>All pages in the Web site should include this menu file. Here is how it can be done:</p>
<pre style="font-size: 1.3 em;   	color: blue;  	margin: 10px;  	padding:10px;  	background: #FFFFB3">&lt;html&gt;
 &lt;body&gt;

 &lt;div&gt;
 &lt;?php include("menu.php"); ?&gt;
 &lt;/div&gt;

 &lt;h1&gt;Welcome to my home page.&lt;/h1&gt;
 &lt;p&gt;Some text.&lt;/p&gt;

 &lt;/body&gt;
 &lt;/html&gt;</pre>
<p>If you look at the source code of the page above (in a browser), it will look like this:</p>
<pre style="font-size: 1.3 em;   	color: blue;  	margin: 10px;  	padding:10px;  	background: #FFFFB3">&lt;html&gt;
 &lt;body&gt;

 &lt;div&gt;
 &lt;a href="/default.php"&gt;Home&lt;/a&gt;
 &lt;a href="/tutorials.php"&gt;Tutorials&lt;/a&gt;
 &lt;a href="/references.php"&gt;References&lt;/a&gt;
 &lt;a href="/examples.php"&gt;Examples&lt;/a&gt;
 &lt;a href="/about.php"&gt;About Us&lt;/a&gt;
 &lt;a href="/contact.php"&gt;Contact Us&lt;/a&gt;
 &lt;/div&gt;

 &lt;h1&gt;Welcome to my home page!&lt;/h1&gt;
 &lt;p&gt;Some text.&lt;/p&gt;

 &lt;/body&gt;
 &lt;/html&gt;</pre>
<p>PHP require() Function</p>
<p>The require() function is identical to include(), except that it handles errors differently.</p>
<p>If an error occurs, the include() function generates a warning, but the script will continue execution. The require() generates a fatal error, and the script will stop.<br />
Error Example include() Function</p>
<pre style="font-size: 1.3 em;   	color: blue;  	margin: 10px;  	padding:10px;  	background: #FFFFB3">&lt;html&gt;
 &lt;body&gt;

 &lt;?php
 include("wrongFile.php");
 echo "Hello World!";
 ?&gt;

 &lt;/body&gt;
 &lt;/html&gt;</pre>
<p>Error message:</p>
<pre style="font-size: 1.3 em;   	color: blue;  	margin: 10px;  	padding:10px;  	background: #FFFFB3"><strong>Warning:</strong> include(wrongFile.php) [function.include]:
 failed to open stream:
 No such file or directory in C:\home\website\test.php on line 5

 <strong>Warning:</strong> include() [function.include]:
 Failed opening 'wrongFile.php' for inclusion
 (include_path='.;C:\php5\pear')
 in C:\home\website\test.php on line 5

 Hello World!</pre>
<p>Notice that the echo statement is executed! This is because a Warning does not stop the script execution.<br />
Error Example require() Function</p>
<p>Now, let&#8217;s run the same example with the require() function.</p>
<pre style="font-size: 1.3 em;   	color: blue;  	margin: 10px;  	padding:10px;  	background: #FFFFB3">&lt;html&gt;
 &lt;body&gt;

 &lt;?php
 require("wrongFile.php");
 echo "Hello World!";
 ?&gt;

 &lt;/body&gt;
 &lt;/html&gt;</pre>
<p>Error message:</p>
<pre style="font-size: 1.3 em;   	color: blue;  	margin: 10px;  	padding:10px;  	background: #FFFFB3"><strong>Warning:</strong> require(wrongFile.php) [function.require]:
 failed to open stream:
 No such file or directory in C:\home\website\test.php on line 5

 <strong>Fatal error:</strong> require() [function.require]:
 Failed opening required 'wrongFile.php'
 (include_path='.;C:\php5\pear')
 in C:\home\website\test.php on line 5</pre>
<p>The echo statement is not executed, because the script execution stopped after the fatal error.</p>
<p>It is recommended to use the require() function instead of include(), because scripts should not continue after an error.</p>
<p><script type="text/javascript">// <![CDATA[
        google_ad_client = "pub-9932804508693643"; /* 468x60_shoutbux */ google_ad_slot = "0201046266"; google_ad_width = 468; google_ad_height = 60;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d798').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d798" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fwww.shoutbux.com%2Fphp-include-file%2F&amp;submitHeadline=PHP+Include+File&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-include-file%2F&amp;title=PHP+Include+File" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-include-file%2F&amp;title=PHP+Include+File" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.shoutbux.com%2Fphp-include-file%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.shoutbux.com%2Fphp-include-file%2F&amp;title=PHP+Include+File" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-include-file%2F&amp;bm_description=PHP+Include+File" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.shoutbux.com%2Fphp-include-file%2F&amp;T=PHP+Include+File" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-include-file%2F&amp;title=PHP+Include+File" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-include-file%2F&amp;title=PHP+Include+File" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.shoutbux.com%2Fphp-include-file%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-include-file%2F" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+PHP+Include+File+@+http%3A%2F%2Fwww.shoutbux.com%2Fphp-include-file%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.shoutbux.com%2Fphp-include-file%2F&amp;t=PHP+Include+File" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d798').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shoutbux.com/php-include-file/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Connecting to MySQL in PHP</title>
		<link>http://www.shoutbux.com/connecting-to-mysql-in-php/</link>
		<comments>http://www.shoutbux.com/connecting-to-mysql-in-php/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 15:43:51 +0000</pubDate>
		<dc:creator>zemog</dc:creator>
				<category><![CDATA[Tutorial - PHP]]></category>
		<category><![CDATA[closing a connection in php]]></category>
		<category><![CDATA[how to connect to mysql]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql_close]]></category>
		<category><![CDATA[mysql_connect]]></category>
		<category><![CDATA[mysql_error]]></category>

		<guid isPermaLink="false">http://www.shoutbux.com/?p=795</guid>
		<description><![CDATA[The free MySQL database is very often used with PHP.]]></description>
			<content:encoded><![CDATA[<p><strong>Create a Connection to a MySQL Database</strong></p>
<p>Before you can access data in a database, you must create a connection to the database.</p>
<p>In PHP, this is done with the mysql_connect() function.<br />
Syntax</p>
<pre style="font-size: 1.3 em;   	color: blue;  	margin: 10px;  	padding:10px;  	background: #FFFFB3"><code>mysql_connect(servername,username,password);</code></pre>
<p>Where</p>
<p>servername = Optional. Specifies the server to connect to. Default value is &#8220;localhost:3306&#8243;<br />
username = Optional. Specifies the username to log in with. Default value is the name of the user that owns the server process<br />
password = Optional. Specifies the password to log in with. Default is &#8220;&#8221;</p>
<p>Note: There are more available parameters, but the ones listed above are the most important. Visit our full PHP MySQL Reference for more details.<br />
Example</p>
<p>In the following example we store the connection in a variable ($con) for later use in the script. The &#8220;die&#8221; part will be executed if the connection fails:</p>
<pre style="font-size: 1.3 em;
 	color: blue;
	margin: 10px;
	padding:10px;
	background: #FFFFB3"><code>&lt;?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// some code
?&gt; </code></pre>
<p><strong>Closing a Connection</strong></p>
<p>The connection will be closed automatically when the script ends. To close the connection before, use the mysql_close() function:</p>
<pre style="font-size: 1.3 em;
 	color: blue;
	margin: 10px;
	padding:10px;
	background: #FFFFB3"><code>&lt;?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// some code

mysql_close($con);
?&gt; </code></pre>
<p><script type="text/javascript">// <![CDATA[
        google_ad_client = "pub-9932804508693643"; /* 468x60_shoutbux */ google_ad_slot = "0201046266"; google_ad_width = 468; google_ad_height = 60;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d795').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d795" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fwww.shoutbux.com%2Fconnecting-to-mysql-in-php%2F&amp;submitHeadline=Connecting+to+MySQL+in+PHP&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.shoutbux.com%2Fconnecting-to-mysql-in-php%2F&amp;title=Connecting+to+MySQL+in+PHP" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.shoutbux.com%2Fconnecting-to-mysql-in-php%2F&amp;title=Connecting+to+MySQL+in+PHP" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.shoutbux.com%2Fconnecting-to-mysql-in-php%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.shoutbux.com%2Fconnecting-to-mysql-in-php%2F&amp;title=Connecting+to+MySQL+in+PHP" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fwww.shoutbux.com%2Fconnecting-to-mysql-in-php%2F&amp;bm_description=Connecting+to+MySQL+in+PHP" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.shoutbux.com%2Fconnecting-to-mysql-in-php%2F&amp;T=Connecting+to+MySQL+in+PHP" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fconnecting-to-mysql-in-php%2F&amp;title=Connecting+to+MySQL+in+PHP" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fconnecting-to-mysql-in-php%2F&amp;title=Connecting+to+MySQL+in+PHP" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.shoutbux.com%2Fconnecting-to-mysql-in-php%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fwww.shoutbux.com%2Fconnecting-to-mysql-in-php%2F" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Connecting+to+MySQL+in+PHP+@+http%3A%2F%2Fwww.shoutbux.com%2Fconnecting-to-mysql-in-php%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.shoutbux.com%2Fconnecting-to-mysql-in-php%2F&amp;t=Connecting+to+MySQL+in+PHP" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d795').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shoutbux.com/connecting-to-mysql-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP IF&#8230; Else Statement</title>
		<link>http://www.shoutbux.com/php-if-else-statement/</link>
		<comments>http://www.shoutbux.com/php-if-else-statement/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 15:36:10 +0000</pubDate>
		<dc:creator>zemog</dc:creator>
				<category><![CDATA[Tutorial - PHP]]></category>
		<category><![CDATA[else if]]></category>
		<category><![CDATA[if else statement php]]></category>
		<category><![CDATA[if elseif]]></category>
		<category><![CDATA[php conditions]]></category>

		<guid isPermaLink="false">http://www.shoutbux.com/?p=793</guid>
		<description><![CDATA[Conditional statements are used to perform different actions based on different conditions.]]></description>
			<content:encoded><![CDATA[<h2>Conditional Statements</h2>
<p>Very often when you write code, you want to perform different actions for  different decisions.</p>
<p>You can use conditional statements in your code to do this.</p>
<p>In PHP we have the following conditional statements:</p>
<ul>
<li><strong>if statement</strong> &#8211; use this statement to execute some code only if a specified condition is true</li>
<li><strong>if&#8230;else statement</strong> &#8211; use this statement to execute some code if a condition is true and another  	code if the condition is false</li>
<li><strong>if&#8230;elseif&#8230;.else statement</strong> &#8211; use this statement to select one of  	several blocks of code to be executed</li>
<li><strong>switch statement</strong> &#8211; use this statement to select one of many blocks of code to be executed</li>
</ul>
<h2>The if Statement</h2>
<p>Use the if statement to execute some code only if a specified condition is true.</p>
<h3>Syntax</h3>
<pre style="font-size: 1.3 em;   	color: blue;  	margin: 10px;  	padding:10px;  	background: #FFFFB3"><code>if (condition) code to be executed if condition is true;</code></pre>
<p>The following example will output &#8220;Have a nice weekend!&#8221; if the current day is Friday:</p>
<pre style="font-size: 1.3 em;   	color: blue;  	margin: 10px;  	padding:10px;  	background: #FFFFB3">&lt;html&gt;
 &lt;body&gt;

 &lt;?php
 $d=date("D");
 if ($d=="Fri") echo "Have a nice weekend!";
 ?&gt;

 &lt;/body&gt;
 &lt;/html&gt;</pre>
<p>Notice that there is no ..else.. in this syntax. You tell the browser to execute some code only if the specified condition is true.</p>
<h2>The if&#8230;else Statement</h2>
<p>Use the if&#8230;.else statement to execute some code if a condition is true and another code if a  condition is false.</p>
<h3>Syntax</h3>
<pre style="font-size: 1.3 em;   	color: blue;  	margin: 10px;  	padding:10px;  	background: #FFFFB3">if (<em>condition</em>)
 <em>code to be executed if condition is true;</em>
 else
 <em>code to be executed if condition is false;</em></pre>
<p>Example</p>
<p>The following example will output &#8220;Have a nice weekend!&#8221; if the current day is Friday, otherwise it will output &#8220;Have a nice day!&#8221;:</p>
<pre style="font-size: 1.3 em;   	color: blue;  	margin: 10px;  	padding:10px;  	background: #FFFFB3">&lt;html&gt;
 &lt;body&gt;

 &lt;?php
 $d=date("D");
 if ($d=="Fri")
 echo "Have a nice weekend!";
 else
 echo "Have a nice day!";
 ?&gt;

 &lt;/body&gt;
 &lt;/html&gt;</pre>
<p>If more than one line should be executed if a condition is true/false, the lines should be enclosed within curly braces:</p>
<pre style="font-size: 1.3 em;   	color: blue;  	margin: 10px;  	padding:10px;  	background: #FFFFB3">&lt;html&gt;
 &lt;body&gt;

 &lt;?php
 $d=date("D");
 if ($d=="Fri")
 {
 echo "Hello!&lt;br /&gt;";
 echo "Have a nice weekend!";
 echo "See you on Monday!";
 }
 ?&gt;

 &lt;/body&gt;
 &lt;/html&gt;</pre>
<h2>The <strong>if&#8230;elseif&#8230;.else</strong> Statement</h2>
<p>Use the if&#8230;.elseif&#8230;else statement to select one of several blocks of code to be executed.</p>
<h3>Syntax</h3>
<pre style="font-size: 1.3 em;   	color: blue;  	margin: 10px;  	padding:10px;  	background: #FFFFB3">if (<em>condition</em>)
 <em>code to be executed if condition is true;</em>
 elseif (<em>condition</em>)
 <em>code to be executed if condition is true;
 </em>else
 <em>code to be executed if condition is false;</em></pre>
<p>Example</p>
<p>The following example will output &#8220;Have a nice weekend!&#8221; if the current day is Friday, and &#8220;Have a nice Sunday!&#8221; if the current day is Sunday. Otherwise it will output &#8220;Have a nice day!&#8221;:</p>
<pre style="font-size: 1.3 em;   	color: blue;  	margin: 10px;  	padding:10px;  	background: #FFFFB3">&lt;html&gt;
 &lt;body&gt;

 &lt;?php
 $d=date("D");
 if ($d=="Fri")
 echo "Have a nice weekend!";
 elseif ($d=="Sun")
 echo "Have a nice Sunday!";
 else
 echo "Have a nice day!";
 ?&gt;

 &lt;/body&gt;
 &lt;/html&gt;</pre>
<p><script type="text/javascript">// <![CDATA[
       google_ad_client = "pub-9932804508693643"; /* 468x60_shoutbux */ google_ad_slot = "0201046266"; google_ad_width = 468; google_ad_height = 60;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d793').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d793" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fwww.shoutbux.com%2Fphp-if-else-statement%2F&amp;submitHeadline=PHP+IF%26%238230%3B+Else+Statement&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-if-else-statement%2F&amp;title=PHP+IF%26%238230%3B+Else+Statement" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-if-else-statement%2F&amp;title=PHP+IF%26%238230%3B+Else+Statement" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.shoutbux.com%2Fphp-if-else-statement%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.shoutbux.com%2Fphp-if-else-statement%2F&amp;title=PHP+IF%26%238230%3B+Else+Statement" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-if-else-statement%2F&amp;bm_description=PHP+IF%26%238230%3B+Else+Statement" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.shoutbux.com%2Fphp-if-else-statement%2F&amp;T=PHP+IF%26%238230%3B+Else+Statement" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-if-else-statement%2F&amp;title=PHP+IF%26%238230%3B+Else+Statement" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-if-else-statement%2F&amp;title=PHP+IF%26%238230%3B+Else+Statement" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.shoutbux.com%2Fphp-if-else-statement%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-if-else-statement%2F" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+PHP+IF%26%238230%3B+Else+Statement+@+http%3A%2F%2Fwww.shoutbux.com%2Fphp-if-else-statement%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.shoutbux.com%2Fphp-if-else-statement%2F&amp;t=PHP+IF%26%238230%3B+Else+Statement" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d793').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shoutbux.com/php-if-else-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Loops</title>
		<link>http://www.shoutbux.com/php-loops/</link>
		<comments>http://www.shoutbux.com/php-loops/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 14:53:34 +0000</pubDate>
		<dc:creator>zemog</dc:creator>
				<category><![CDATA[Tutorial - PHP]]></category>
		<category><![CDATA[for each loop]]></category>
		<category><![CDATA[for loop]]></category>
		<category><![CDATA[php loops]]></category>

		<guid isPermaLink="false">http://www.shoutbux.com/?p=775</guid>
		<description><![CDATA[Loops execute a block of code a specified number of times, or while a specified condition is true.]]></description>
			<content:encoded><![CDATA[<p><strong>The for Loop</strong></p>
<p>The for loop is used when you know in advance how many times the script should run.</p>
<p>Syntax</p>
<pre style="font-size: 1.3 em;
 	color: blue;
	margin: 10px;
	padding:10px;
	background: #FFFFB3"><code>for (init; condition; increment)
{
code to be executed;
}</code></pre>
<p>Parameters:</p>
<p>* init: Mostly used to set a counter (but can be any code to be executed once at the beginning of the loop)<br />
* condition: Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, the loop ends.<br />
* increment: Mostly used to increment a counter (but can be any code to be executed at the end of the loop)</p>
<p>Note: Each of the parameters above can be empty, or have multiple expressions (separated by commas).<br />
Example</p>
<p>The example below defines a loop that starts with i=1. The loop will continue to run as long as i is less than, or equal to 5. i will increase by 1 each time the loop runs:</p>
<pre  style="font-size: 1.3 em;
 	color: blue;
	margin: 10px;
	padding:10px;
	background: #FFFFB3"><code>&lt;html&gt;
&lt;body&gt;

&lt;?php
for ($i=1; $i&lt;=5; $i++)
  {
  echo "The number is " . $i . "&lt;br /&gt;";
  }
?&gt;

&lt;/body&gt;
&lt;/html&gt; </code></pre>
<p><strong>The foreach Loop</strong></p>
<p>The foreach loop is used to loop through arrays.</p>
<p>Syntax</p>
<pre style="font-size: 1.3 em;
 	color: blue;
	margin: 10px;
	padding:10px;
	background: #FFFFB3"><code>foreach ($array as $value)
  {
  code to be executed;
  }</code></pre>
<p>For every loop iteration, the value of the current array element is assigned to $value (and the array pointer is moved by one) &#8211; so on the next loop iteration, you&#8217;ll be looking at the next array value.<br />
Example</p>
<p>The following example demonstrates a loop that will print the values of the given array:</p>
<pre style="font-size: 1.3 em;
 	color: blue;
	margin: 10px;
	padding:10px;
	background: #FFFFB3"><code>&lt;html&gt;
&lt;body&gt;

&lt;?php
$x=array("one","two","three");
foreach ($x as $value)
  {
  echo $value . "&lt;br /&gt;";
  }
?&gt;

&lt;/body&gt;
&lt;/html&gt; </code></pre>
<p><script type="text/javascript">// <![CDATA[
         google_ad_client = "pub-9932804508693643"; /* 468x60_shoutbux */ google_ad_slot = "0201046266"; google_ad_width = 468; google_ad_height = 60;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d775').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d775" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fwww.shoutbux.com%2Fphp-loops%2F&amp;submitHeadline=PHP+Loops&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-loops%2F&amp;title=PHP+Loops" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-loops%2F&amp;title=PHP+Loops" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.shoutbux.com%2Fphp-loops%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.shoutbux.com%2Fphp-loops%2F&amp;title=PHP+Loops" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-loops%2F&amp;bm_description=PHP+Loops" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.shoutbux.com%2Fphp-loops%2F&amp;T=PHP+Loops" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-loops%2F&amp;title=PHP+Loops" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-loops%2F&amp;title=PHP+Loops" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.shoutbux.com%2Fphp-loops%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-loops%2F" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+PHP+Loops+@+http%3A%2F%2Fwww.shoutbux.com%2Fphp-loops%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.shoutbux.com%2Fphp-loops%2F&amp;t=PHP+Loops" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d775').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shoutbux.com/php-loops/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Error Handling</title>
		<link>http://www.shoutbux.com/php-error-handling/</link>
		<comments>http://www.shoutbux.com/php-error-handling/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 14:40:18 +0000</pubDate>
		<dc:creator>zemog</dc:creator>
				<category><![CDATA[Tutorial - PHP]]></category>
		<category><![CDATA[PHP Error Handling]]></category>

		<guid isPermaLink="false">http://www.shoutbux.com/?p=769</guid>
		<description><![CDATA[The default error handling in PHP is very simple. An error message with filename, line number and a message describing the error is sent to the browser.]]></description>
			<content:encoded><![CDATA[<p>When creating scripts and web applications, error handling is an important part. If your code lacks error checking code, your program may look very unprofessional and you may be open to security risks.</p>
<p>This tutorial will teach you how to use the die function.</p>
<p><strong>Basic Error Handling: Using the die() function</strong></p>
<p>The first example shows a simple script that opens a text file:</p>
<pre>
<code>&lt;?php
        $file=fopen("welcome.txt","r");
?&gt; </code></pre>
<p>If the file does not exist you might get an error like this:</p>
<pre>
<code>Warning: fopen(welcome.txt) [function.fopen]: failed to open stream:
No such file or directory in C:\webfolder\test.php on line 2</code></pre>
<p>
To avoid that the user gets an error message like the one above, we test if the file exist before we try to access it:<br />
</p>
<pre>
<code>&lt;?php
if(!file_exists("welcome.txt"))
  {
  die("File not found");
  }
else
  {
  $file=fopen("welcome.txt","r");
  }
?&gt; </code></pre>
<p>
Now if the file does not exist you get an error like this:</p>
<pre><code>File not found </code></pre>
<p>The code above is more efficient than the earlier code, because it uses a simple error handling mechanism to stop the script after the error.</p>
<p>However, simply stopping the script is not always the right way to go. Let&#8217;s take a look at alternative PHP functions for handling errors.</p>
<p><script type="text/javascript">// <![CDATA[
       google_ad_client = "pub-9932804508693643"; /* 468x60_shoutbux */ google_ad_slot = "0201046266"; google_ad_width = 468; google_ad_height = 60;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d769').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d769" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fwww.shoutbux.com%2Fphp-error-handling%2F&amp;submitHeadline=PHP+Error+Handling&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-error-handling%2F&amp;title=PHP+Error+Handling" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-error-handling%2F&amp;title=PHP+Error+Handling" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.shoutbux.com%2Fphp-error-handling%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.shoutbux.com%2Fphp-error-handling%2F&amp;title=PHP+Error+Handling" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-error-handling%2F&amp;bm_description=PHP+Error+Handling" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.shoutbux.com%2Fphp-error-handling%2F&amp;T=PHP+Error+Handling" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-error-handling%2F&amp;title=PHP+Error+Handling" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-error-handling%2F&amp;title=PHP+Error+Handling" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.shoutbux.com%2Fphp-error-handling%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fwww.shoutbux.com%2Fphp-error-handling%2F" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+PHP+Error+Handling+@+http%3A%2F%2Fwww.shoutbux.com%2Fphp-error-handling%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.shoutbux.com%2Fphp-error-handling%2F&amp;t=PHP+Error+Handling" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d769').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shoutbux.com/php-error-handling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preventing SQL Injections in Joomla</title>
		<link>http://www.shoutbux.com/preventing-sql-injections-in-joomla/</link>
		<comments>http://www.shoutbux.com/preventing-sql-injections-in-joomla/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 04:53:00 +0000</pubDate>
		<dc:creator>zemog</dc:creator>
				<category><![CDATA[Tutorial - PHP]]></category>
		<category><![CDATA[casting a number]]></category>
		<category><![CDATA[sql injections]]></category>
		<category><![CDATA[xss attacks]]></category>

		<guid isPermaLink="false">http://www.shoutbux.com/?p=678</guid>
		<description><![CDATA[How to secure your script from sql injections.]]></description>
			<content:encoded><![CDATA[<p>Written by Anthony Ferrara</p>
<p>Recently, I&#8217;ve been noticing a lot of misconceptions about how to protect code in 3pd extensions from SQL injection.  To be honest, using JRequest is not enough by far!!!  I hope to cover some thing here about some methods to prevent SQL attacks.  It&#8217;s not that difficult; there are a few simple things you can do to prevent injection attacks.  I&#8217;ll go through them one by one, and show some examples of each.<br />
Force the type you want</p>
<p>Basically, if you are expecting an integer, force it to be an integer (or a float).  So, if you have a variable that you are expecting to be an integer, cast it to an integer&#8230; For example:</p>
<p>$sql = &#8216;UPDATE #__mytable SET `id` = &#8216; . (int) $int;</p>
<p>If you want to insert a date, then use JDate, and it&#8217;ll give you back a valid mysql date each time&#8230;</p>
<p>$date =&#038; JFactory::getDate($mydate);<br />
$sql = &#8216;UPDATE #__mytable SET `date` = &#8216; . $db->quote( $date->toMySQL(), false); </p>
<p>ALWAYS escape your strings</p>
<p>Well, anytime you take a string from user input (I always escape everything from a variable, it&#8217;s extra insurance), you should escape it using:</p>
<p>$sql = &#8216;UPDATE #__mytable SET `string` = &#8216; . $db->quote( $db->getEscaped( $string ), false ); </p>
<p>Notice that we&#8217;re using 2 functions there.  One escapes the string, and the other wraps it in quotes.  If you&#8217;ve noticed the second parameter for $db->quote() is false&#8230; If you leave that out, or set it to true, then it&#8217;ll escape it for you.  So that string becomes:</p>
<p>$sql = &#8216;UPDATE #__mytable SET `string` = &#8216; . $db->quote( $string ); </p>
<p>Prevent DOS attacks</p>
<p>In a where clause, if you use a LIKE command, you can have a DOS vulnerability by not escaping the special wildcard characters % and _.  Joomla has a facility to do this for you!  $db->getEscaped can take a second parameter which will escape those characters for you.  NOTE:  You only should escape these for strings used in a LIKE comparison.  So:</p>
<p>$sql = &#8216;UPDATE #__mytable SET &#8230;. WHERE `string` LIKE &#8216;.<br />
              $db->quote( $db->getEscaped( $string, true ), false );</p>
<p>Preventing XSS Attacks</p>
<p>Most people just get data using JRequest::getVar()&#8230; But there are a whole bunch of other methods that exist which actually force type much better.  Here are some those methods:</p>
<p>For Integers:</p>
<p>$int = JRequest::getInt( $name, $default ); </p>
<p>For Floats (decimals):</p>
<p>$float = JRequest::getFloat( $name, $default ); </p>
<p>For boolean values (true/false):</p>
<p>$bool = JRequest::getBool( $name, $default ); </p>
<p>For &#8220;words&#8221; (only allows alpha characters, and the _ character)</p>
<p>$word = JRequest::getWord( $name, $default ); </p>
<p>For &#8220;commands&#8221; (Allows alpha characters, numeric characters, . &#8211; and _ )</p>
<p>$cmd = JRequest::getCMD( $name, $default );</p>
<p>For NON-HTML text (all HTML will be stripped)</p>
<p>$string = JRequest::getString( $name, $default ); </p>
<p>Source: http://developer.joomla.org/security/articles-tutorials/258-preventing-sql-injections.html</p>
<p><script type="text/javascript">// <![CDATA[
           google_ad_client = "pub-9932804508693643"; /* 468x60_shoutbux */ google_ad_slot = "0201046266"; google_ad_width = 468; google_ad_height = 60;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d678').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d678" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fwww.shoutbux.com%2Fpreventing-sql-injections-in-joomla%2F&amp;submitHeadline=Preventing+SQL+Injections+in+Joomla&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.shoutbux.com%2Fpreventing-sql-injections-in-joomla%2F&amp;title=Preventing+SQL+Injections+in+Joomla" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.shoutbux.com%2Fpreventing-sql-injections-in-joomla%2F&amp;title=Preventing+SQL+Injections+in+Joomla" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.shoutbux.com%2Fpreventing-sql-injections-in-joomla%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.shoutbux.com%2Fpreventing-sql-injections-in-joomla%2F&amp;title=Preventing+SQL+Injections+in+Joomla" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fwww.shoutbux.com%2Fpreventing-sql-injections-in-joomla%2F&amp;bm_description=Preventing+SQL+Injections+in+Joomla" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.shoutbux.com%2Fpreventing-sql-injections-in-joomla%2F&amp;T=Preventing+SQL+Injections+in+Joomla" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fpreventing-sql-injections-in-joomla%2F&amp;title=Preventing+SQL+Injections+in+Joomla" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fpreventing-sql-injections-in-joomla%2F&amp;title=Preventing+SQL+Injections+in+Joomla" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.shoutbux.com%2Fpreventing-sql-injections-in-joomla%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fwww.shoutbux.com%2Fpreventing-sql-injections-in-joomla%2F" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Preventing+SQL+Injections+in+Joomla+@+http%3A%2F%2Fwww.shoutbux.com%2Fpreventing-sql-injections-in-joomla%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.shoutbux.com%2Fpreventing-sql-injections-in-joomla%2F&amp;t=Preventing+SQL+Injections+in+Joomla" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d678').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shoutbux.com/preventing-sql-injections-in-joomla/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get live currency using PHP</title>
		<link>http://www.shoutbux.com/get-live-currency-using-php/</link>
		<comments>http://www.shoutbux.com/get-live-currency-using-php/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 17:40:20 +0000</pubDate>
		<dc:creator>zemog</dc:creator>
				<category><![CDATA[Tutorial - PHP]]></category>
		<category><![CDATA[cURL]]></category>
		<category><![CDATA[currency conversion]]></category>
		<category><![CDATA[Get live currency using PHP]]></category>
		<category><![CDATA[live currency feed]]></category>
		<category><![CDATA[string manipulation]]></category>

		<guid isPermaLink="false">http://www.shoutbux.com/?p=594</guid>
		<description><![CDATA[Have you ever wondered how you can get a currency feed? Many sites are offering this but it is not for free. Use Google's currency converter for a free feed instead]]></description>
			<content:encoded><![CDATA[<p>Few years ago I made a script that will get a live currency from a certain site and display the information on my page. After a few hours of looking into my old file, I can not find my script so I made a new one. I remember I use the cURL function but I forgot the website I used to get the data (am I too forgetful these day? hmm)</p>
<p>Without any other choice, I have to use my friend Google for some clues. Throwing different search keys such as &#8220;currency converter using PHP&#8221;, &#8220;live currency feed&#8221;, &#8220;currency feed&#8221;, &#8220;pesos to usd conversion using php&#8221;, etc., I came across with this forum http://forums.whirlpool.net.au/forum-replies-archive.cfm/783963.html in which the last thread says</p>
<blockquote><p>Could always use Google.</p>
<p><a style="color: navy; text-decoration: none;" rel="nofollow" href="http://www.google.com.au/search?q=100+aud+in+usd" target="_blank">www.google.com.au/search?q=100+aud+in+usd<img src="http://forums.whirlpool.net.au/im/extlink.gif" border="0" alt="" vspace="2" width="6" height="6" align="top" /></a></p></blockquote>
<p>Yeah, why not use Google&#8217;s own conversion!</p>
<p>So here is the code.</p>
<pre style="font-size: 1.3 em;
 	color: blue;
	margin: 10px;
	padding:10px;
	background: #FFFFB3"><code>
if (function_exists('curl_init'))
{
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,
'http://www.google.com.au/search?hl=en&amp;amp; q=1+usd+in+php&amp;amp;btnG=Search&amp;amp;
meta=&amp;amp;aq=f&amp;amp;oq=');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT,
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');

$content = curl_exec($ch);

curl_close($ch);

$position1 	= strpos($content,"1 U.S. dollar =");
$cleandata 	= substr($content,$position1+15,7);
echo $cleandata;
}
else
{
echo "sorry no cURL here";
}
</code></pre>
<p>Let me discuss to you some points</p>
<p>First there is the condition to check whether cURL is available of not. -&gt; if (function_exists(&#8216;curl_init&#8217;))<br />
The most interesting part here is the url</p>
<p>http://www.google.com.au/search?hl=en&amp;q=1+usd+in+php&amp;btnG=Search&amp;meta=&amp;aq=f&amp;oq=</p>
<p>How did I get that url? What I did was put the query &#8220;1 usd in php&#8221; which translate to 1 US dollar to philippine peso. Then the result appears</p>
<div id="attachment_596" class="wp-caption alignnone" style="width: 310px"><img class="size-medium wp-image-596" title="1 usd to php" src="http://www.shoutbux.com/wp-content/uploads/2009/11/conversion-300x118.jpg" alt="1 usd to php" width="300" height="118" /><p class="wp-caption-text">1 usd to php</p></div>
<p>Now that Google have displayed the result, all we need to do is read the html file using cURL and using some <a href="http://www.shoutbux.com/string-manipulation-in-php/">string manipulations</a> you can easily get what you want. In the example above you should get the value 47.499</p>
<p><script type="text/javascript">// <![CDATA[
       google_ad_client = "pub-9932804508693643"; /* 468x60_shoutbux */ google_ad_slot = "0201046266"; google_ad_width = 468; google_ad_height = 60;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">
</script></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d594').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Bookmark It</em></strong></a>
<br />
<div class="d594" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http%3A%2F%2Fwww.shoutbux.com%2Fget-live-currency-using-php%2F&amp;submitHeadline=Get+live+currency+using+PHP&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.shoutbux.com%2Fget-live-currency-using-php%2F&amp;title=Get+live+currency+using+PHP" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.shoutbux.com%2Fget-live-currency-using-php%2F&amp;title=Get+live+currency+using+PHP" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.shoutbux.com%2Fget-live-currency-using-php%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fwww.shoutbux.com%2Fget-live-currency-using-php%2F&amp;title=Get+live+currency+using+PHP" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http%3A%2F%2Fwww.shoutbux.com%2Fget-live-currency-using-php%2F&amp;bm_description=Get+live+currency+using+PHP" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fwww.shoutbux.com%2Fget-live-currency-using-php%2F&amp;T=Get+live+currency+using+PHP" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fget-live-currency-using-php%2F&amp;title=Get+live+currency+using+PHP" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.shoutbux.com%2Fget-live-currency-using-php%2F&amp;title=Get+live+currency+using+PHP" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.shoutbux.com%2Fget-live-currency-using-php%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http%3A%2F%2Fwww.shoutbux.com%2Fget-live-currency-using-php%2F" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Get+live+currency+using+PHP+@+http%3A%2F%2Fwww.shoutbux.com%2Fget-live-currency-using-php%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fwww.shoutbux.com%2Fget-live-currency-using-php%2F&amp;t=Get+live+currency+using+PHP" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shoutbux.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d594').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shoutbux.com/get-live-currency-using-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
