<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Team Tutorials»  | Team Tutorials</title>
	
	<link>http://teamtutorials.com</link>
	<description />
	<lastBuildDate>Thu, 18 Jun 2009 22:08:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /><meta xmlns="http://pipes.yahoo.com" name="pipes" content="noprocess" /><image><link>http://www.teamtutorials.com</link><url>http://www.teamtutorials.com/teamtutorials.gif</url><title>Team Tutorials Clover Logo</title></image><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/TeamTutorials" type="application/rss+xml" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">TeamTutorials</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>How to Parse a CSV File Using PHP</title>
		<link>http://teamtutorials.com/web-development-tutorials/how-to-parse-a-csv-file-using-php</link>
		<comments>http://teamtutorials.com/web-development-tutorials/how-to-parse-a-csv-file-using-php#comments</comments>
		<pubDate>Thu, 18 Jun 2009 22:07:06 +0000</pubDate>
		<dc:creator>John Ward</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Development Tutorials]]></category>
		<category><![CDATA[comma separated value. fgetcsv]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[fopen]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://teamtutorials.com/?p=1850</guid>
		<description><![CDATA[In this tutorial you will learn a simple way to parse CSV files using PHP and output the text of the fields you need. This tutorial is not going to go into what you can do with the data once you get it from the CSV as the possibilities are endless. We will simply show you how to get the data into an array in PHP.]]></description>
			<content:encoded><![CDATA[<p>In this tutorial you will learn a simple way to parse CSV files using PHP and output the text of the fields you need. This tutorial is not going to go into what you can do with the data once you get it from the CSV as the possibilities are endless. We will simply show you how to get the data into an array in PHP.</p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2009/06/test.csv"><br />
First you can download our test.csv file here. </a></p>
<p>Now we are going to open the file for reading using the fopen() function in PHP. Will will specify the location of the file and also the mode in which we want to open it. In this case we are using the &#8220;R&#8221; mode which stands for read. Other possible uses of this function can be found on the <a href="http://us2.php.net/manual/en/function.fopen.php">manual page for fopen()</a>.</p>
<pre class="brush: php;">
&lt;?php

$handle = fopen(&quot;test.csv&quot;, &quot;r&quot;);

?&gt;
</pre>
<p>Next we are going to create a while loop. We will use this loop to parse each line of the CSV.</p>
<pre class="brush: php;">
&lt;?php
$handle = fopen(&quot;test.csv&quot;, &quot;r&quot;);

while () {

}
?&gt;
</pre>
<p>Next we are going to use the <a href="http://us3.php.net/manual/en/function.fgetcsv.php">fgetcsv() function </a>to &#8220;split&#8221; each line of our CSV file into an array called $data. When there are no lines left the condition will be false and will end the loop. In the fgetcsv() function we will pass the file handle, length (optional) and the separating character (which is a comma in this case.<br />
test</p>
<pre class="brush: php;">
&lt;?php

$handle = fopen(&quot;test.csv&quot;, &quot;r&quot;);

while (($data = fgetcsv($handle, 5000, &quot;,&quot;)) !== FALSE) {

}
?&gt;
</pre>
<p>*note: If you data fields are encapsulated using a character such as &#8211; (for ease of example) you can specify the enclosure filed like so: fgetcsv($handle, 5000, &#8220;,&#8221;,&#8221;-&#8221;). By default the enclosure character is a double quote, but the function will also handle no enclosure character.</p>
<p>Next all we have to do is echo the fields that we want to see. We will use the field number in the array to do this. I will echo the second value in the CSV.</p>
<pre class="brush: php;">
&lt;?php

$handle = fopen(&quot;test.csv&quot;, &quot;r&quot;);
$row = 1;
while (($data = fgetcsv($handle, 5000, &quot;,&quot;)) !== FALSE) {
	echo $data[2];
	echo &quot;&lt;/br&gt;&quot;;
}
?&gt;
</pre>
<p>Another note. If you do not know which value the field you are looking for will be in the array just print the array like this:</p>
<pre class="brush: php;">
&lt;?php

$handle = fopen(&quot;test.csv&quot;, &quot;r&quot;);

while (($data = fgetcsv($handle, 5000, &quot;,&quot;)) !== FALSE) {
	echo &quot;&lt;pre&gt;&quot;;
	print_r($data);
	echo &quot;&lt;pre&gt;&quot;;
}
?&gt;
</pre>
<p>As you can see it is pretty simple to parse csv using this method. You may have issue with memory if you try to open large files using fopen. in that case you will want to read the file line-by-line, but that is another tutorial.<br />
<h3>Related Posts</h3>
<ul class="related_post">
<li>March 30, 2009 &#8212; <a href="http://teamtutorials.com/other-tutorials/how-to-return-mysql-results-to-a-table" title="How to Return MySQL Results to a Table">How to Return MySQL Results to a Table (4)</a></li>
<li>March 13, 2009 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/editing-mysql-data-using-php" title="Editing MySQL Data Using PHP">Editing MySQL Data Using PHP (17)</a></li>
<li>February 22, 2009 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/how-to-get-a-users-geo-location" title="How to Get a Users Geo Location?">How to Get a Users Geo Location? (5)</a></li>
<li>September 21, 2008 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/creating-checkboxes-based-on-sql-results" title="Creating Checkboxes Based on SQL Results">Creating Checkboxes Based on SQL Results (3)</a></li>
<li>August 25, 2008 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/simple-php-website-templates" title="Simple PHP Website Templates">Simple PHP Website Templates (8)</a></li>
</ul>
<img src="http://teamtutorials.com/?ak_action=api_record_view&id=1850&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://teamtutorials.com/web-development-tutorials/how-to-parse-a-csv-file-using-php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Validating Email Address with PHP and AJAX</title>
		<link>http://teamtutorials.com/web-development-tutorials/validating-email-address-with-php-and-ajax</link>
		<comments>http://teamtutorials.com/web-development-tutorials/validating-email-address-with-php-and-ajax#comments</comments>
		<pubDate>Mon, 08 Jun 2009 07:05:27 +0000</pubDate>
		<dc:creator>Mike Maguire</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[HTML Tutorials]]></category>
		<category><![CDATA[JavaScriptTutorials]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Development Tutorials]]></category>

		<guid isPermaLink="false">http://teamtutorials.com/?p=1837</guid>
		<description><![CDATA[This tutorial will walk you through checking for an e-mail to be valid as the user is filling out the form without having to reload the page.]]></description>
			<content:encoded><![CDATA[<p>This tutorial will walk you through checking for an e-mail to be valid as the user is filling out the form without having to reload the page. Bear in mind, that there is no way to make sure that we get an accurate working e-mail every time. All we can do is prevent users from using extremely random ones or for domains that don’t exist. I was working on a form for a new website that is going to require users to create an account and was browsing the web to see what people use to validate e-mails, other than the obvious choice of running it through a reg-ex (regular expression), and I came across a site that showed me a feature of php that can be useful. The original post can be found over at <a href="http://davidwalsh.name/php-email-validator-mx-dns-record-check">David Walsh’s website</a>. I think that using that this php function as well as a reg-ex and running them from an AJAX call should do the trick. So let’s get started. You can get the images we will be using <a href="http://teamtutorials.com/files/email_validation_images.zip">here. </a>First we will make the form that will call the functions. Since this will be our user account creator we’ll call it adduser.php. (I’m leaving out the default HTML/CSS as you can do that however you like – you may also note that this file could be an HTML as there is no php in this section  – this is just a part of the much larger file that I am working with (-:). </p>
<pre class="brush: html;">
&lt;script type=&quot;text/javascript&quot; src=&quot;includes/js/validate_email.js&quot;&gt;&lt;/script&gt;

&lt;form method=&quot;post&quot; action=&quot;register.php&quot; name=&quot;user&quot;&gt;
&lt;h2&gt;User Creation&lt;/h2&gt;
UserName (Display Name):&lt;input type=&quot;text&quot; name=&quot;display_name&quot; id=&quot;display_name&quot;/&gt; &lt;br /&gt;
First Name:&lt;input type=&quot;text&quot; name=&quot;fname&quot; id=&quot;name&quot;/&gt;&lt;br /&gt;
Last Name:&lt;input type=&quot;text&quot; name=&quot;lname&quot; id=&quot;surname&quot;/&gt;&lt;br /&gt;
E-mail:&lt;input type=&quot;text&quot; name=&quot;email&quot; id=&quot;email&quot; onBlur=&quot;checkEmail()&quot;/&gt;&lt;div id=&quot;emailflag&quot; style=&quot;display:inline;&quot;&gt;&lt;img src=&quot;images/failure.gif&quot;&gt;&lt;/div&gt;&lt;br /&gt;
Password:&lt;input type=&quot;password&quot; name=&quot;pass&quot; id=&quot;pass&quot;/&gt;
Confirm PW:&lt;input type=&quot;password&quot; name=&quot;pass2&quot; id=&quot;pass2&quot; /&gt;
&lt;br  /&gt;
&lt;/form&gt;
</pre>
<p>Only a few things to note here: the onBlur command in the e-mail textbox is the first. This is going to call the email function (which is included in the script include at the beginning of the file) every time that textbox is tabbed or clicked away from. Also, note the div after the textbox, that contains the failure image now as we will use that ID to change the image later. Next, we need to create the php file that will actually do the validation when the AJAX calls it. Let’s call this file validate_email.php. I’ll break this one down a little to explain what’s going on. </p>
<pre class="brush: php;">
&lt;?php
if (isset($_GET['email'])){
	isValidEmail($_GET['email']);
}
</pre>
<p>This couple of lines simply checks for a variable to be set and if it is, calls the function to validate the address – this will prevent from someone going straight to this file or going to it with a blank string. As you can see we pass the value in the variable to the function. </p>
<pre class="brush: php;">
function isValidEmail($email)
	{
	$myReg=&quot;/^[A-Za-z0-9\._-]+@[A-Za-z0-9_-]+\.([A-Za-z0-9_-][A-Za-z0-9_]+)$/&quot;;
		if(preg_match($myReg, $email)){
			if(domain_exists($_GET['email']))
			{
				echo(&quot;&lt;img src=\&quot;images/success.gif\&quot;&gt;&quot;);
			}
			else
			{
				echo(&quot;&lt;img src=\&quot;images/failure.gif\&quot;&gt;&quot;);
			}
		}
		else
		{
			echo(&quot;&lt;img src=\&quot;images/failure.gif\&quot;&gt;&quot;);
		}
	}
</pre>
<p>The function looks worse than it actually is due to the reg-ex. They can be a little confusing, but once you understand what it does, it’s not that bad….but that is another tutorial. For now just know it checks the string that is passed to it to be formatted correctly. First we set the reg-ex and then we pass the address to it through the preg_match command. This will process the string to match the reg-ex and output true or false. If it passes validation, we then pass it to our function to check the MX record. If that passes we echo the path to success.gif (which is a green check-mark), otherwise we echo the path to failure.gif (which is a red x). Note that for these to work you will need to put the images in the proper locations or change the path to the images. Finally, in this file we need to create the domain_exists fcuntion that we called in the above section of code. </p>
<pre class="brush: php;">
function domain_exists($email,$record = 'MX')
{
	list($user,$domain) = split('@',$email);
	return checkdnsrr($domain,$record);
}
?&gt;
</pre>
<p>This simply runs the e-mail(after splitting the email at the @ symbol) through the checkdnsrr which checks for the MX record to be retrievable from the domain name. This essentially just checks for a server to be responding at that domain name. Technically we could still put an e-mail that doesn’t exist, as all we check is for the domain to exist. Next, we need to create the AJAX call file. We’ll call this file validate_email.js.</p>
<pre class="brush: js;">
function checkEmail(){
	httpObject = getHTTPObject();
	if (httpObject != null) {
		if (!document.getElementById('email').value== &quot;&quot;){
			httpObject.open(&quot;GET&quot;, &quot;../includes/php/checkemail.php?email=&quot;+document.getElementById('email').value, true);
			httpObject.send(null);
			httpObject.onreadystatechange = setImage;
		}
		else
		{
			document.getElementById('emailflag').innerHTML = &quot;&lt;img src=\&quot;images/failure.gif\&quot;&gt;&quot;;
		}
	}
}
</pre>
<p>This file has 3 functions in it. The first one is the function that we are calling from the form in the first file. This function calls the getHTTPObject function to initialize the AJAX call that we will use. Next, we check for the email field in the form to contain information and if it does, we do an HTTP GET request to call the php file and pass it the email that is currently in the textbox. If it contains no data it sets the div that is created right after the textbox to contain the failure image. Once the HTTP object state changes, we call the function that will pass the image contents. </p>
<pre class="brush: js;">
function getHTTPObject(){
if (window.ActiveXObject) return new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
else if (window.XMLHttpRequest) return new XMLHttpRequest();
else {
alert(&quot;Your browser does not support AJAX.&quot;);
return null;
}}
</pre>
<p>This function declares the httpObject that we will be using and throws an error in the browser if it does not support the call. </p>
<pre class="brush: js;">
function setImage(){
if(httpObject.readyState == 4){
document.getElementById('emailflag').innerHTML = httpObject.responseText;
}}
</pre>
<p>This final function checks for the state of the object to be 4 (completed) and if it is it sets the innerHTML of the ID from the form to whatever was echoed from the PHP file (either the success or the failure gif). That completes the files. Ensure that all the files are in the right place. I have my php file in /includes/php/validate_email.php and the javascript file is /includes/js/validate_email.js. </p>
<p><img src="http://teamtutorials.com/wp-content/uploads/2009/06/ajax_php_email_validation_01.jpg" alt="ajax_php_email_validation_01" title="ajax_php_email_validation_01" width="464" height="177" class="alignnone size-full wp-image-1839" /></p>
<p>This is the form that should be shown when you go to the main form. </p>
<p><img src="http://teamtutorials.com/wp-content/uploads/2009/06/ajax_php_email_validation_02.jpg" alt="ajax_php_email_validation_02" title="ajax_php_email_validation_02" width="471" height="189" class="alignnone size-full wp-image-1840" /></p>
<p>When you type a valid e-mail into the e-mail box, the checkmark should appear where the X was like above.</p>
<p><img src="http://teamtutorials.com/wp-content/uploads/2009/06/ajax_php_email_validation_03.jpg" alt="ajax_php_email_validation_03" title="ajax_php_email_validation_03" width="453" height="184" class="alignnone size-full wp-image-1838" /></p>
<p>If you put in a improperly formatted e-mail like above, it should switch it back to an X. It will also go back to an X if you blank out the text box. </p>
<p>That completes this tutorial. Some of this can be hard to follow so please leave any questions or comments you have in the comments sections and we’ll help you out where we can. Also, I made the reg-ex fit as many things as I could, if you find a valid e-mail that it fails, please let me know so that I can modify it to work. Thanks for viewing this tutorial and I hope it was easy to follow. </p>
<h3>Other Related Tutorials</h3>
<ul class="related_post">
<li>June 10, 2008 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/professional-javascript-based-photo-viewer" title="Professional Javascript Based Photo Viewer">Professional Javascript Based Photo Viewer (6)</a></li>
<li>April 10, 2007 &#8212; <a href="http://teamtutorials.com/photoshop-tutorials/photoshop-darkness-logo-tutorial" title="Photoshop Darkness Logo Tutorial">Photoshop Darkness Logo Tutorial (46)</a></li>
<li>September 6, 2007 &#8212; <a href="http://teamtutorials.com/windows-tutorials/make-an-invisble-folder-on-the-desktop" title="Make an invisible folder on the desktop.">Make an invisible folder on the desktop. (7)</a></li>
<li>June 6, 2007 &#8212; <a href="http://teamtutorials.com/windows-tutorials/configure-windows-xp-automatic-updates" title="Configure Windows XP Automatic Updates">Configure Windows XP Automatic Updates (0)</a></li>
<li>May 31, 2007 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/introduction-to-online-advertising" title="Introduction To Online Advertising">Introduction To Online Advertising (3)</a></li>
</ul>
<img src="http://teamtutorials.com/?ak_action=api_record_view&id=1837&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://teamtutorials.com/web-development-tutorials/validating-email-address-with-php-and-ajax/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Disable UAC(User Access Control) in Windows Vista</title>
		<link>http://teamtutorials.com/other-tutorials/disable-uacuser-access-control-in-windows-vista</link>
		<comments>http://teamtutorials.com/other-tutorials/disable-uacuser-access-control-in-windows-vista#comments</comments>
		<pubDate>Sat, 09 May 2009 00:41:30 +0000</pubDate>
		<dc:creator>Mike Maguire</dc:creator>
				<category><![CDATA[Administration Tutorials]]></category>
		<category><![CDATA[Other Tutorials]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Windows Tutorials]]></category>
		<category><![CDATA[uac]]></category>
		<category><![CDATA[user access control]]></category>
		<category><![CDATA[vista]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://teamtutorials.com/?p=1826</guid>
		<description><![CDATA[This tutorial will walk you through disabling the UAC that is enabled on all Windows Vista machines by default.  ]]></description>
			<content:encoded><![CDATA[<p>UAC is a security feature in Windows Vista that is designed to make sure you want to do certain tasks. UAC requires permission to perform all of the following tasks:<br />
•	Changes to system-wide settings or to files in %SystemRoot% or %ProgramFiles%<br />
•	Installing and uninstalling applications<br />
•	Installing device drivers<br />
•	Installing ActiveX controls<br />
•	Changing settings for Windows Firewall<br />
•	Changing UAC settings<br />
•	Configuring Windows Update<br />
•	Adding or removing user accounts<br />
•	Changing a user’s account type<br />
•	Configuring Parental Controls<br />
•	Running Task Scheduler<br />
•	Restoring backed-up system files<br />
•	Viewing or changing another user’s folders and files<br />
Many users have asked if and how they can disable this from prompting them every time they want to do these tasks. This tutorial will walk you through disabling it.</p>
<p><img src="http://teamtutorials.com/wp-content/uploads/2009/05/disable_uac_in_vista_01.jpg" alt="disable_uac_in_vista_01" title="disable_uac_in_vista_01" width="407" height="561" class="alignnone size-full wp-image-1827" /></p>
<p>To start you will want to click on the Start orb and type msconfig into the box for it to find what you are looking for (alternatively if you use the classic start menu, click on run and type msconfig and press enter).</p>
<p><img src="http://teamtutorials.com/wp-content/uploads/2009/05/disable_uac_in_vista_02.jpg" alt="disable_uac_in_vista_02" title="disable_uac_in_vista_02" width="585" height="389" class="alignnone size-full wp-image-1828" /></p>
<p>The above window will appear. This is the configuration setting for a lot of Windows components and features. We will not want to click on the tools tab to open the section with our UAC settings.</p>
<p><img src="http://teamtutorials.com/wp-content/uploads/2009/05/disable_uac_in_vista_03.jpg" alt="disable_uac_in_vista_03" title="disable_uac_in_vista_03" width="585" height="389" class="alignnone size-full wp-image-1829" /></p>
<p>This is the tools tab. This tab allows you access to some pre built scripts and features of the Windows Operating System. </p>
<p><img src="http://teamtutorials.com/wp-content/uploads/2009/05/disable_uac_in_vista_04.jpg" alt="disable_uac_in_vista_04" title="disable_uac_in_vista_04" width="585" height="389" class="alignnone size-full wp-image-1830" /></p>
<p>Scroll down until you see Disable UAC. Click on it once and click the Launch button at the bottom of the screen.</p>
<p><img src="http://teamtutorials.com/wp-content/uploads/2009/05/disable_uac_in_vista_05.jpg" alt="disable_uac_in_vista_05" title="disable_uac_in_vista_05" width="677" height="340" class="alignnone size-full wp-image-1831" /></p>
<p>The above window will appear to let you know that is has completed successfully or give you any error it may have encountered. That is all there is to it. As you may have noticed, there is also an option to Enable UAC which will allow you to turn it back on if you decide you would like to. I hope this tutorial was easy to follow and thanks for reading. </p>
<img src="http://teamtutorials.com/?ak_action=api_record_view&id=1826&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://teamtutorials.com/other-tutorials/disable-uacuser-access-control-in-windows-vista/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Launch of WootStat – The Best Woot Tracker on Facebook</title>
		<link>http://teamtutorials.com/off-topic/launch-of-wootstat-the-top-woot-tracker-on-facebook</link>
		<comments>http://teamtutorials.com/off-topic/launch-of-wootstat-the-top-woot-tracker-on-facebook#comments</comments>
		<pubDate>Mon, 06 Apr 2009 23:36:30 +0000</pubDate>
		<dc:creator>John Ward</dc:creator>
				<category><![CDATA[Off Topic]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[scraping]]></category>
		<category><![CDATA[woot]]></category>

		<guid isPermaLink="false">http://teamtutorials.com/?p=1813</guid>
		<description><![CDATA[Introducing WootStat, the premier <a href="http://www.wootstat.com">Woot tracker for Facebook</a>. Mike and myself decided to work with the Facebook API. We ended up created a <a href="http://www.facebook.com/apps/application.php?id=33428063902">cool application for tracking items on Woot.com</a>. After checking out the competiton we stack up pretty well. I think we have the most features of any WootTracker on Facebook. ]]></description>
			<content:encoded><![CDATA[<p><!--noadsense--><br />
Introducing WootStat, the premier <a href="http://www.wootstat.com">Woot tracker for Facebook</a>. Mike and myself decided to work with the Facebook API. We ended up created a <a href="http://www.facebook.com/apps/application.php?id=33428063902">cool application for tracking items on Woot.com</a>. After checking out the competiton we stack up pretty well. I think we have the most features of any WootTracker on Facebook. </p>
<p><a href="http://www.facebook.com/apps/application.php?id=33428063902"><img src="http://teamtutorials.com/wp-content/uploads/2009/04/woot-stat-facebook.gif" alt="Woot Stat on Facebook" title="Woot Stat on Facebook" width="396" height="396" class="alignnone size-full wp-image-1816" /></a></p>
<p>WootStat offers:</p>
<ul>
<li>User Voting</li>
<li>Price Comparison</li>
<li>Sharing Capabilities</li>
<li>Past items</li>
<li>Woot-Off Predictions</li>
<li>Top Users</li>
<li>Best and Worst Items</li>
<li>Email Notifications</li>
<li>&#8230;and more to come</li>
</ul>
<p>The user who refers the most friends this month will <strong>win a $50 NewEgg.com Gift Card</strong>. At the time of this post the leader has only 3 referrals.<a href="http://apps.facebook.com/wootstat/addfriends.php"> All you have to do is add WootStat and then Invite Your Friends.</a></p>
<p>If you want to check out the app you can check it out at <a href="http://wootstat.com/">WootStat.com</a>.</p>
<p><a href="http://www.facebook.com/apps/application.php?id=33428063902">See the Facebook about page</a></p>
<p><a href="http://www.woot.com/WhatIsWoot.aspx">What is woot?</a></p>
<p>I hope that this would lead to some Facebook API tutorials, but I can&#8217;t promise anything. As usual if you have any question post them below or feel free to use the contact form. We generally respond to all inquires.<br />
<h3>Related Posts</h3>
<ul class="related_post">
<li>September 21, 2008 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/creating-checkboxes-based-on-sql-results" title="Creating Checkboxes Based on SQL Results">Creating Checkboxes Based on SQL Results (3)</a></li>
<li>September 7, 2008 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/jquery-pop-over-effects" title="jQuery Pop Over Effects">jQuery Pop Over Effects (3)</a></li>
<li>August 18, 2008 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/password-verification-and-strength-checker" title="Password Verification and Strength Checker">Password Verification and Strength Checker (7)</a></li>
<li>August 13, 2008 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/javascript-progress-bar-2" title="JavaScript Progress Bar 2">JavaScript Progress Bar 2 (4)</a></li>
<li>August 12, 2008 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/html-tutorials/javascript-progress-bar" title="JavaScript Progress Bar">JavaScript Progress Bar (2)</a></li>
</ul>
<img src="http://teamtutorials.com/?ak_action=api_record_view&id=1813&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://teamtutorials.com/off-topic/launch-of-wootstat-the-top-woot-tracker-on-facebook/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Return MySQL Results to a Table</title>
		<link>http://teamtutorials.com/other-tutorials/how-to-return-mysql-results-to-a-table</link>
		<comments>http://teamtutorials.com/other-tutorials/how-to-return-mysql-results-to-a-table#comments</comments>
		<pubDate>Tue, 31 Mar 2009 00:24:08 +0000</pubDate>
		<dc:creator>John Ward</dc:creator>
				<category><![CDATA[Other Tutorials]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tables]]></category>

		<guid isPermaLink="false">http://teamtutorials.com/?p=1804</guid>
		<description><![CDATA[This question has been asked several times lately and I wanted to clear this up. This is a very easy concept once you get it down. In order to display the results from a MySQL query into a table will will store the results in an array and then echo out each row in a while loop.]]></description>
			<content:encoded><![CDATA[<p>This question has been asked several times lately and I wanted to clear this up. This is a very easy concept once you get it down. In order to display the results from a MySQL query into a table will will store the results in an array and then echo out each row in a while loop.</p>
<p>First off. I am going to use a table that I created in the past tutorials on this site.</p>
<p>The table contains the following fields:</p>
<p>ID &#8211; auto generated integer<br />
FName &#8211; First Name, varchar<br />
LName &#8211; Last Name, varchar<br />
PHON &#8211; Phone number, varchar</p>
<p>Create the table and populate some test data if you haven&#8217;t done so already. If you don&#8217;t know how to do this please visit some of our other MySQL tutorials.</p>
<p>Create your database connection</p>
<pre class="brush: php;">
&amp;lt;?php
//create a database connection
mysql_connect(&amp;quot;localhost&amp;quot;,&amp;quot;your username&amp;quot;,&amp;quot;password&amp;quot;) or die(&amp;quot;Error: &amp;quot;.mysqlerror());
//select your database
mysql_select_db(&amp;quot;your db&amp;quot;);
?&amp;gt;
</pre>
<p>Next we need to setup the table. We will add the column headings.</p>
<pre class="brush: php;">
&amp;lt;?php
//create a database connection
mysql_connect(&amp;quot;localhost&amp;quot;,&amp;quot;your username&amp;quot;,&amp;quot;password&amp;quot;) or die(&amp;quot;Error: &amp;quot;.mysqlerror());
//select your database
mysql_select_db(&amp;quot;your db&amp;quot;);
?&amp;gt;

&amp;lt;html&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;table border=1&amp;gt;
  &amp;lt;tr&amp;gt;
   &amp;lt;th&amp;gt;ID&amp;lt;/th&amp;gt;
   &amp;lt;th&amp;gt;First Name&amp;lt;/th&amp;gt;
   &amp;lt;th&amp;gt;Last Name&amp;lt;/th&amp;gt;
   &amp;lt;th&amp;gt;Phone Number&amp;lt;/th&amp;gt;
  &amp;lt;/tr&amp;gt;
</pre>
<p>As you can see above we ended our PHP code and create an HTML table. The TR tage is used to defined a table row and the TH tag is used for Table Headings.</p>
<p>In php you can &#8220;break&#8221; out of code and execute HTML and then continue writing php code. Do do this you simply end your php code with then start a new <?php tag when you want to start again.</p>
<p>So the next setup will be to add the php code to select our items from the database.</p>
<pre class="brush: php;">
&amp;lt;?php
//create a database connection
mysql_connect(&amp;quot;localhost&amp;quot;,&amp;quot;your username&amp;quot;,&amp;quot;password&amp;quot;) or die(&amp;quot;Error: &amp;quot;.mysqlerror());
//select your database
mysql_select_db(&amp;quot;your db&amp;quot;);
?&amp;gt;

&amp;lt;html&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;table border=1&amp;gt;
  &amp;lt;tr&amp;gt;
   &amp;lt;th&amp;gt;ID&amp;lt;/th&amp;gt;
   &amp;lt;th&amp;gt;First Name&amp;lt;/th&amp;gt;
   &amp;lt;th&amp;gt;Last Name&amp;lt;/th&amp;gt;
   &amp;lt;th&amp;gt;Phone Number&amp;lt;/th&amp;gt;
  &amp;lt;/tr&amp;gt;

&amp;lt;?php
//create the query
$query = mysql_query(&amp;quot;select * from `TestTable`&amp;quot;);

//return the array and loop through each row
while ($row = mysql_fetch_array($query)){

	$id = $row['ID'];
	$fname = $row['FName'];
	$lname = $row['LName'];
	$phone = $row['PHON'];

?&amp;gt;
</pre>
<p>Above you will see that we executed a query and returned the results as an array. We will loop through each record and echo the results in the table. Take notice that I DID NOT CLOSE the if statment here on purpose.</p>
<p>Now to we will add the HTML for the rows that are returned. We will use php and echo the results.</p>
<pre class="brush: php;">
&amp;lt;?php
//create a database connection
mysql_connect(&amp;quot;localhost&amp;quot;,&amp;quot;your username&amp;quot;,&amp;quot;password&amp;quot;) or die(&amp;quot;Error: &amp;quot;.mysqlerror());
//select your database
mysql_select_db(&amp;quot;your db&amp;quot;);
?&amp;gt;

&amp;lt;html&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;table border=1&amp;gt;
  &amp;lt;tr&amp;gt;
   &amp;lt;th&amp;gt;ID&amp;lt;/th&amp;gt;
   &amp;lt;th&amp;gt;First Name&amp;lt;/th&amp;gt;
   &amp;lt;th&amp;gt;Last Name&amp;lt;/th&amp;gt;
   &amp;lt;th&amp;gt;Phone Number&amp;lt;/th&amp;gt;
  &amp;lt;/tr&amp;gt;

&amp;lt;?php
//create the query
$query = mysql_query(&amp;quot;select * from `TestTable`&amp;quot;);

//return the array and loop through each row
while ($row = mysql_fetch_array($query)){

	$id = $row['ID'];
	$fname = $row['FName'];
	$lname = $row['LName'];
	$phone = $row['PHON'];

?&amp;gt;

  &amp;lt;tr&amp;gt;
   &amp;lt;th&amp;gt;&amp;lt;?php echo $id;?&amp;gt;&amp;lt;/th&amp;gt;
   &amp;lt;th&amp;gt;&amp;lt;?php echo $fname;?&amp;gt;&amp;lt;/th&amp;gt;
   &amp;lt;th&amp;gt;&amp;lt;?php echo $lname;?&amp;gt;&amp;lt;/th&amp;gt;
   &amp;lt;th&amp;gt;&amp;lt;?php echo $phone;?&amp;gt;&amp;lt;/th&amp;gt;
  &amp;lt;/tr&amp;gt;
</pre>
<p>Now all we have to do is end the if statement and close all of our open HTML tags.</p>
<pre class="brush: php;">
&amp;lt;?php
//create a database connection
mysql_connect(&amp;quot;localhost&amp;quot;,&amp;quot;your username&amp;quot;,&amp;quot;password&amp;quot;) or die(&amp;quot;Error: &amp;quot;.mysqlerror());
//select your database
mysql_select_db(&amp;quot;your db&amp;quot;);
?&amp;gt;

&amp;lt;html&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;table border=1&amp;gt;
  &amp;lt;tr&amp;gt;
   &amp;lt;th&amp;gt;ID&amp;lt;/th&amp;gt;
   &amp;lt;th&amp;gt;First Name&amp;lt;/th&amp;gt;
   &amp;lt;th&amp;gt;Last Name&amp;lt;/th&amp;gt;
   &amp;lt;th&amp;gt;Phone Number&amp;lt;/th&amp;gt;
  &amp;lt;/tr&amp;gt;

&amp;lt;?php
//create the query
$query = mysql_query(&amp;quot;select * from `TestTable`&amp;quot;);

//return the array and loop through each row
while ($row = mysql_fetch_array($query)){

	$id = $row['ID'];
	$fname = $row['FName'];
	$lname = $row['LName'];
	$phone = $row['PHON'];

?&amp;gt;

  &amp;lt;tr&amp;gt;
   &amp;lt;th&amp;gt;&amp;lt;?php echo $id;?&amp;gt;&amp;lt;/th&amp;gt;
   &amp;lt;th&amp;gt;&amp;lt;?php echo $fname;?&amp;gt;&amp;lt;/th&amp;gt;
   &amp;lt;th&amp;gt;&amp;lt;?php echo $lname;?&amp;gt;&amp;lt;/th&amp;gt;
   &amp;lt;th&amp;gt;&amp;lt;?php echo $phone;?&amp;gt;&amp;lt;/th&amp;gt;
  &amp;lt;/tr&amp;gt;

&amp;lt;?php } //this ends the if?&amp;gt;

&amp;lt;/table&amp;gt;
&amp;lt;/html&amp;gt;
</pre>
<p>If you do it right you will get something like this:<br />
<img src="http://teamtutorials.com/wp-content/uploads/2009/03/phptable.jpg" alt="Display PHP results in Table" title="Display PHP results in Table" width="303" height="298" class="alignnone size-full wp-image-1805" /></p>
<h3>Related Posts</h3>
<ul class="related_post">
<li>March 13, 2009 -- <a href="http://teamtutorials.com/web-development-tutorials/editing-mysql-data-using-php" title="Editing MySQL Data Using PHP">Editing MySQL Data Using PHP (17)</a></li>
<li>September 21, 2008 -- <a href="http://teamtutorials.com/web-development-tutorials/creating-checkboxes-based-on-sql-results" title="Creating Checkboxes Based on SQL Results">Creating Checkboxes Based on SQL Results (3)</a></li>
<li>August 25, 2008 -- <a href="http://teamtutorials.com/web-development-tutorials/simple-php-website-templates" title="Simple PHP Website Templates">Simple PHP Website Templates (8)</a></li>
<li>July 16, 2008 -- <a href="http://teamtutorials.com/web-development-tutorials/php-tutorials/creating-a-form-that-will-search-a-mysql-database" title="Creating a Form that will Search a MySQL Database">Creating a Form that will Search a MySQL Database (32)</a></li>
<li>June 18, 2008 -- <a href="http://teamtutorials.com/web-development-tutorials/setting-up-a-wamp-server" title="Setting Up a WAMP Server">Setting Up a WAMP Server (30)</a></li>
</ul>
<img src="http://teamtutorials.com/?ak_action=api_record_view&id=1804&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://teamtutorials.com/other-tutorials/how-to-return-mysql-results-to-a-table/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Editing MySQL Data Using PHP</title>
		<link>http://teamtutorials.com/web-development-tutorials/editing-mysql-data-using-php</link>
		<comments>http://teamtutorials.com/web-development-tutorials/editing-mysql-data-using-php#comments</comments>
		<pubDate>Fri, 13 Mar 2009 17:01:43 +0000</pubDate>
		<dc:creator>John Ward</dc:creator>
				<category><![CDATA[Database Tutorials]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Development Tutorials]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://teamtutorials.com/?p=1795</guid>
		<description><![CDATA[We have had a few tutorial that show how to display and add data to a MySQL database. Now I am going to show you how to edit a row in your database. In previous examples we setup a table whcih contains: ID, FName, LName and PHON. We will be retreiving the data, making changes, then updating the row in the database. This tutorial is design for the user to update there own information so we will only be editing row for this user.]]></description>
			<content:encoded><![CDATA[<p>We have had a few tutorial that show how to display and add data to a MySQL database. Now I am going to show you how to edit a row in your database. In previous examples we setup a table which contains: ID, FName, LName and PHON. We will be retreiving the data, making changes, then updating the row in the database. This tutorial is designed for the user to update there own information so we will only be editing row for this user. </p>
<p>If you haven&#8217;t taken a look at the past tutorials you may want to:<br />
<a href="http://teamtutorials.com/web-development-tutorials/how-to-access-a-mysql-database-using-php">How to Access a MySQL Database Using PHP</a><br />
<a href="http://teamtutorials.com/web-development-tutorials/php-tutorials/inserting-data-into-a-mysql-database-using-php">Inserting Data Into a MySQL Database using PHP</a></p>
<p>You are going to need to create the database if you haven&#8217;t done so yet. I called my table `TestTable` and populated the following fields:</p>
<p>ID &#8211; Integer, Auto increment<br />
FName &#8211; varchar (first name)<br />
LName &#8211; varchar (last name)<br />
PHON &#8211; varchar (phone number)</p>
<p>Populate some test data into your database and you should be ready to go.</p>
<p>We are going to need to create two files in order to edit the date.<br />
editinfo.php &#8211; We will get the user info from the DB and put it into a form.<br />
updateinfo.php &#8211; We will send the changes from editinfo.php to this for and update the database.</p>
<p>First create editinfo.php</p>
<p>We are going to connect to the database:</p>
<pre class="brush: php;">
&lt;?php
mysql_connect(&quot;localhost&quot;,&quot;USERNAME&quot;,&quot;PASSWORD&quot;) or die(&quot;Error: &quot;.mysql_error()); //add your DB username and password
mysql_select_db(&quot;DBNAME&quot;);//add your dbname

?&gt;
</pre>
<p> Since I am only editing 1 row I am going to just use the user with ID 1. If you were using this in an application you would have this information store when the user is authenticated, but I am going to hard code the user ID into my queries for the example.</p>
<pre class="brush: php;">
&lt;?php
mysql_connect(&quot;localhost&quot;,&quot;USERNAME&quot;,&quot;PASSWORD&quot;) or die(&quot;Error: &quot;.mysql_error()); //add your DB username and password
mysql_select_db(&quot;DBNAME&quot;);//add your dbname

$sql = &quot;select * from `TestTable` where ID = 1&quot;;
$query = mysql_query($sql);

while ($row = mysql_fetch_array($query)){

	$id = $row['ID'];
	$fname = $row['FName'];
	$lname = $row['LName'];
	$phone = $row['PHON'];

	//we will echo these into the proper fields

}
mysql_free_result($query);
?&gt;
</pre>
<p>As you can see by the comment about, we will return the rows as an array called $row. Once we build the HTML form we will be able to populate the data into the field. Now I will start with the HTML for the form.</p>
<pre class="brush: html;">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Edit User Info&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;form action=&quot;updateinfo.php&quot; method=&quot;post&quot;&gt;

&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The important things to note in the HTML above is the form action and method. Action is where we will be sending the data. We want to pass all the changes to updateinfo.php and then updateinfo.php will update the database. The method is the method that we will be using to transmit the variables. You can use either GET or POST variables. GET variables will be displayed in the url, for this example we do not want that, we can you the post method.</p>
<p>Next add the form fields. We will use the input tag for this form. Pay attention to the different values if you are not familiar with them. </p>
<p>type=&#8221;text&#8221; &#8211;just means we are using a text field<br />
value=&#8221;" &#8211;this is what the box will display by default.<br />
name=&#8221;id&#8221; &#8211;this is what the variable will be named. This is what we will send to updateinfo.php</p>
<pre class="brush: html;">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Edit User Info&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;form action=&quot;updateinfo.php&quot; method=&quot;post&quot;&gt;

userid:&lt;br/&gt;
&lt;input type=&quot;text&quot; value=&quot;&quot; name=&quot;id&quot; disabled/&gt;

&lt;br/&gt;

Last Name:&lt;br/&gt;
&lt;input type=&quot;text&quot; value=&quot;&quot; name=&quot;fname&quot;/&gt;

&lt;br/&gt;

Last Name:&lt;br/&gt;
&lt;input type=&quot;text&quot; value=&quot;&quot; name=&quot;lname&quot;/&gt;

&lt;br/&gt;

Phone Number:&lt;br/&gt;
&lt;input type=&quot;text&quot; value=&quot;&quot; name=&quot;phon&quot;/&gt;

&lt;/br&gt;

&lt;input type=&quot;submit&quot; value=&quot;submit changes&quot;/&gt;

&lt;/form&gt;

&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Now we have the fields setup. You will notice that the input box for id is disable. This is because I do not want the user to be able to change their ID.</p>
<p>Next step is to populate the form with some data. We will echo the values that we set above in the PHP code.</p>
<pre class="brush: html;">

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Edit User Info&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;form action=&quot;updateinfo.php&quot; method=&quot;post&quot;&gt;

userid:&lt;br/&gt;
&lt;input type=&quot;text&quot; value=&quot;&lt;?php echo $id;?&gt;&quot; name=&quot;id&quot; disabled/&gt;

&lt;br/&gt;

Last Name:&lt;br/&gt;
&lt;input type=&quot;text&quot; value=&quot;&lt;?php echo $fname;?&gt;&quot; name=&quot;fname&quot;/&gt;

&lt;br/&gt;

Last Name:&lt;br/&gt;
&lt;input type=&quot;text&quot; value=&quot;&lt;?php echo $lname;?&gt;&quot; name=&quot;lname&quot;/&gt;

&lt;br/&gt;

Phone Number:&lt;br/&gt;
&lt;input type=&quot;text&quot; value=&quot;&lt;?php echo $phone;?&gt;&quot; name=&quot;phon&quot;/&gt;

&lt;/br&gt;

&lt;input type=&quot;submit&quot; value=&quot;submit changes&quot;/&gt;

&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Now you should have you fields populated. The next step is to create the updateinfo.php file and actually update some data. We will start by capturing the data. First connect to your database.</p>
<pre class="brush: php;">
&lt;?php
mysql_connect(&quot;localhost&quot;,&quot;USERNAME&quot;,&quot;PASSWORD&quot;) or die(&quot;Error: &quot;.mysql_error()); //add your DB username and password
mysql_select_db(&quot;DBNAME&quot;);//add your dbname

//get the variables we transmitted from the form
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$phon = $_POST['phon'];

?&gt;
</pre>
<p>Build the update query and execute.</p>
<pre class="brush: php;">
&lt;?php
mysql_connect(&quot;localhost&quot;,&quot;USERNAME&quot;,&quot;PASSWORD&quot;) or die(&quot;Error: &quot;.mysql_error()); //add your DB username and password
mysql_select_db(&quot;DBNAME&quot;);//add your dbname

//get the variables we transmitted from the form
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$phon = $_POST['phon'];

//replace TestTable with the name of your table
//replace id with the ID of your user
$sql = &quot;UPDATE `TestTable` SET `FName` = '$fname',`LName` = '$lname',`PHON` = '$phon' WHERE `TestTable`.`ID` = '$id' LIMIT 1&quot;;

mysql_query($sql) or die (&quot;Error: &quot;.mysql_error());

echo &quot;Database updated. &lt;a href='editinfo.php'&gt;Return to edit info&lt;/a&gt;&quot;;

?&gt;
</pre>
<p>That is all you need to allow a user to update their info. Now this is a very basic version. If you were to use this on a production web site you would want to do form validation and also protect yourself from sql injection in the update form.</p>
<p>Here is the full source for both files:</p>
<p>editinfo.php</p>
<pre class="brush: html;">
&lt;?php

//replace usernaem,password, and yourdb with the information for your database
mysql_connect(&quot;localhost&quot;,&quot;USERNAME&quot;,&quot;PASSWORD&quot;) or die(&quot;Error: &quot;.mysqlerror());
mysql_select_db(&quot;YOURDB&quot;); 

//replace TestTable with the name of your table
//also in a real app you would get the id dynamically
$sql = &quot;select * from `TestTable` where ID = 1&quot;;
$query = mysql_query($sql);

while ($row = mysql_fetch_array($query)){

	$id = $row['ID'];
	$fname = $row['FName'];
	$lname = $row['LName'];
	$phone = $row['PHON'];

	//we will echo these into the proper fields

}
mysql_free_result($query);
?&gt;

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Edit User Info&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;form action=&quot;updateinfo.php&quot; method=&quot;post&quot;&gt;

userid:&lt;br/&gt;
&lt;input type=&quot;text&quot; value=&quot;&lt;?php echo $id;?&gt;&quot; name=&quot;id&quot; disabled/&gt;

&lt;br/&gt;

Last Name:&lt;br/&gt;
&lt;input type=&quot;text&quot; value=&quot;&lt;?php echo $fname;?&gt;&quot; name=&quot;fname&quot;/&gt;

&lt;br/&gt;

Last Name:&lt;br/&gt;
&lt;input type=&quot;text&quot; value=&quot;&lt;?php echo $lname;?&gt;&quot; name=&quot;lname&quot;/&gt;

&lt;br/&gt;

Phone Number:&lt;br/&gt;
&lt;input type=&quot;text&quot; value=&quot;&lt;?php echo $phone;?&gt;&quot; name=&quot;phon&quot;/&gt;

&lt;/br&gt;

&lt;input type=&quot;submit&quot; value=&quot;submit changes&quot;/&gt;

&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>updateinfo.php</p>
<pre class="brush: php;">
&lt;?php
//replace usernaem,password, and yourdb with the information for your database
mysql_connect(&quot;localhost&quot;,&quot;USERNAME&quot;,&quot;PASSWORD&quot;) or die(&quot;Error: &quot;.mysqlerror());
mysql_select_db(&quot;YOURDB&quot;); 

//get the variables we transmitted from the form
$id = $_POST['id'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$phon = $_POST['phon'];

//replace TestTable with the name of your table
$sql = &quot;UPDATE `TestTable` SET `FName` = '$fname',`LName` = '$lname',`PHON` = '$phon' WHERE `TestTable`.`ID` = '$id' LIMIT 1&quot;;

mysql_query($sql) or die (&quot;Error: &quot;.mysql_error());

echo &quot;Database updated. &lt;a href='editinfo.php'&gt;Return to edit info&lt;/a&gt;&quot;;
?&gt;
</pre>
<p>If you are going to ask a question please take the time to go through the tutorial first. Thanks.</p>
<h3>Related Posts</h3>
<ul class="related_post">
<li>July 16, 2008 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/php-tutorials/creating-a-form-that-will-search-a-mysql-database" title="Creating a Form that will Search a MySQL Database">Creating a Form that will Search a MySQL Database (32)</a></li>
<li>March 30, 2009 &#8212; <a href="http://teamtutorials.com/other-tutorials/how-to-return-mysql-results-to-a-table" title="How to Return MySQL Results to a Table">How to Return MySQL Results to a Table (4)</a></li>
<li>September 21, 2008 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/creating-checkboxes-based-on-sql-results" title="Creating Checkboxes Based on SQL Results">Creating Checkboxes Based on SQL Results (3)</a></li>
<li>June 18, 2008 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/setting-up-a-wamp-server" title="Setting Up a WAMP Server">Setting Up a WAMP Server (30)</a></li>
<li>June 18, 2009 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/how-to-parse-a-csv-file-using-php" title="How to Parse a CSV File Using PHP">How to Parse a CSV File Using PHP (1)</a></li>
</ul>
<img src="http://teamtutorials.com/?ak_action=api_record_view&id=1795&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://teamtutorials.com/web-development-tutorials/editing-mysql-data-using-php/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Handling Errors To Prevent Application Crashes in VB</title>
		<link>http://teamtutorials.com/programming-tutorials/handling-error-to-prevent-application-crashes-in-vb</link>
		<comments>http://teamtutorials.com/programming-tutorials/handling-error-to-prevent-application-crashes-in-vb#comments</comments>
		<pubDate>Fri, 27 Feb 2009 10:35:49 +0000</pubDate>
		<dc:creator>Mike Maguire</dc:creator>
				<category><![CDATA[Programming Tutorials]]></category>
		<category><![CDATA[Visual Basic 2005/2008]]></category>

		<guid isPermaLink="false">http://teamtutorials.com/?p=1776</guid>
		<description><![CDATA[This tutorial will walk you through a very simple but extremely useful function in programming. When you write code you can never guarantee that specific requirements will be met upon execution and therefore errors are always a possibility. As a coder you need to be able foresee these types of issues and catch them before the application crashes and requires the user to restart it and even worse, lose data that they may have been working on.]]></description>
			<content:encoded><![CDATA[<p>This tutorial will walk you through a very simple but extremely useful function in programming. When you write code you can never guarantee that specific requirements will be met upon execution and therefore errors are always a possibility. As a coder you need to be able foresee these types of issues and catch them before the application crashes and requires the user to restart it and even worse, lose data that they may have been working on. To do this, we will use a Try Catch Finally statement. We will go into detail in the tutorial. To start, let’s create a new project in Visual Basic.</p>
<p><img src="http://teamtutorials.com/wp-content/uploads/2009/02/basic_error_handling_in_vb_01.jpg" alt="basic_error_handling_in_vb_01" title="basic_error_handling_in_vb_01" width="228" height="192" class="alignnone size-full wp-image-1777" /></p>
<p>Click on Create next to Project to create our project.</p>
<p><img src="http://teamtutorials.com/wp-content/uploads/2009/02/basic_error_handling_in_vb_02.jpg" alt="basic_error_handling_in_vb_02" title="basic_error_handling_in_vb_02" width="540" height="464" class="alignnone size-full wp-image-1778" /></p>
<p>Name the project what you want and place it where you want as well. I called mine tutorial and stored it in a folder named mike on my desktop. Next we need to make the form. The first picture is what is should look like and the second is the items labeled with what I named each control so that yours can be the same. </p>
<p><img src="http://teamtutorials.com/wp-content/uploads/2009/02/basic_error_handling_in_vb_03.jpg" alt="basic_error_handling_in_vb_03" title="basic_error_handling_in_vb_03" width="208" height="103" class="alignnone size-full wp-image-1779" /><br />
<img src="http://teamtutorials.com/wp-content/uploads/2009/02/basic_error_handling_in_vb_04.jpg" alt="basic_error_handling_in_vb_04" title="basic_error_handling_in_vb_04" width="208" height="103" class="alignnone size-full wp-image-1780" /></p>
<p>Note that the plus sign is just a label with the “+” plus symbol as the text. Then we have two textboxes (txt1 and txt2) and finally a command button (cmdCalculate). Now, let’s double click on the button to begin our programming. </p>
<pre class="brush: vb;">
        Try
            MsgBox(CInt(txt1.Text) + CInt(txt2.Text))
        Catch ex As Exception
            MsgBox(&quot;This message shows when it errors to tell you why:&quot; &amp; ex.Message)
        Finally
            MsgBox(&quot;This message shows whether it errors or not&quot;)
            txt1.Text = Nothing
            txt2.Text = Nothing
  End Try
</pre>
<p>All of this code should go in the sub for the button press. This is all the programming we will have to do to understand what this phrase does and why it can be so useful. First we initialize the “Try” statement. Anything under this section will be run once the code gets to this point. You can put multiple things in here and it will step through them until it completes or errors out. Here, we are attempting to convert anything in the textboxes to an integer so that they can be added together and show the result. Anything in the “Catch” section will be executed in the event that anything in the “Try” statement fails. Here we are popping a message box up and giving the user the information of why it failed. The “ex.message” is whatever message the exception that occurred carries so that we can inform the user of why it crashed. Anything in the finally statement will be executed either way. This is useful for connections and stuff so that whether the transaction fails or completes it will close the connection. In this sample, we are making a message box appear as well as clearing both text boxes whether the process fails or not. Finally we end the try statement.  Let’s run it and make sure it does what it is supposed to.</p>
<p><img src="http://teamtutorials.com/wp-content/uploads/2009/02/basic_error_handling_in_vb_05.jpg" alt="basic_error_handling_in_vb_05" title="basic_error_handling_in_vb_05" width="208" height="103" class="alignnone size-full wp-image-1781" /></p>
<p>Let’s start by putting in two numbers to make sure it adds them together correctly. I put in 34 and 54. </p>
<p><img src="http://teamtutorials.com/wp-content/uploads/2009/02/basic_error_handling_in_vb_06.jpg" alt="basic_error_handling_in_vb_06" title="basic_error_handling_in_vb_06" width="104" height="100" class="alignnone size-full wp-image-1782" /></p>
<p>You should get the above message box if it worked. Mine came to 88 which means it is working as it is expected.</p>
<p><img src="http://teamtutorials.com/wp-content/uploads/2009/02/basic_error_handling_in_vb_07.jpg" alt="basic_error_handling_in_vb_07" title="basic_error_handling_in_vb_07" width="242" height="100" class="alignnone size-full wp-image-1783" /></p>
<p>Then you will get the above message box as well because it is in the finally section of the code which is run either way. The textboxes should now clear as well. Next we will try to make sure our try, catch statement works properly. </p>
<p><img src="http://teamtutorials.com/wp-content/uploads/2009/02/basic_error_handling_in_vb_08.jpg" alt="basic_error_handling_in_vb_08" title="basic_error_handling_in_vb_08" width="208" height="103" class="alignnone size-full wp-image-1784" /></p>
<p>Lets put 34 in the first box and “35t” (thirty five and then the letter t). Then click the calculate button. </p>
<p><img src="http://teamtutorials.com/wp-content/uploads/2009/02/basic_error_handling_in_vb_09.jpg" alt="basic_error_handling_in_vb_09" title="basic_error_handling_in_vb_09" width="548" height="100" class="alignnone size-full wp-image-1785" /></p>
<p>Since we are trying to convert the text in txt2 to an integer and it contains a letter, that won’t work and it will error out with the above message. “Conversion from string “35t” to type ‘Integer’ is not valid” is the text that was stored in “ex.message”. Normally the app would have crashed due to an unhandled exception and made the user start over from scratch (which in our case isn’t a big deal, but when you are working on more advanced apps and a lot of data is involved it can be very annoying to have to start over). </p>
<p>Finally, you will get the message that appears whether the try works or not and the text boxes will be cleared. That concludes this tutorial. I hope you can see why the try, catch, finally statement is so important. It is a very common part of programming and is used to some extent in every language.  Once you get used to it, you can use multiple catch statements to catch different types of errors and do different things based on what type of error is caught. I hope this is helpful and that you were able to understand. Thanks for reading.</p>
<h3>Other Related Tutorials</h3>
<ul class="related_post">
<li>May 8, 2007 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/generate-traffic-with-ekstreme-socializer-plugin-for-wordpress" title="Generate Traffic with Ekstreme  Socializer Plugin for Wordpress">Generate Traffic with Ekstreme  Socializer Plugin for Wordpress (3)</a></li>
<li>June 25, 2007 &#8212; <a href="http://teamtutorials.com/photoshop-tutorials/blue-and-chrome-text" title="Blue and Chrome Text">Blue and Chrome Text (9)</a></li>
<li>May 22, 2007 &#8212; <a href="http://teamtutorials.com/windows-tutorials/show-file-extension-in-windows-xp" title="Show File Extension in Windows XP">Show File Extension in Windows XP (6)</a></li>
<li>August 13, 2008 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/javascript-progress-bar-2" title="JavaScript Progress Bar 2">JavaScript Progress Bar 2 (4)</a></li>
<li>June 5, 2007 &#8212; <a href="http://teamtutorials.com/site-news/do-you-like-our-kontera-ads" title="Do you like our Kontera Ads?">Do you like our Kontera Ads? (4)</a></li>
</ul>
<img src="http://teamtutorials.com/?ak_action=api_record_view&id=1776&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://teamtutorials.com/programming-tutorials/handling-error-to-prevent-application-crashes-in-vb/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Get a Users Geo Location?</title>
		<link>http://teamtutorials.com/web-development-tutorials/how-to-get-a-users-geo-location</link>
		<comments>http://teamtutorials.com/web-development-tutorials/how-to-get-a-users-geo-location#comments</comments>
		<pubDate>Mon, 23 Feb 2009 00:27:29 +0000</pubDate>
		<dc:creator>John Ward</dc:creator>
				<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[SEO Tutorials]]></category>
		<category><![CDATA[Web Development Tutorials]]></category>
		<category><![CDATA[geo code]]></category>
		<category><![CDATA[geo location]]></category>
		<category><![CDATA[geocoding]]></category>
		<category><![CDATA[max mind]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://teamtutorials.com/?p=1767</guid>
		<description><![CDATA[Every wonder how all of those dating ads know that you are looking for hot girls near (insert your city here)? Well if you are a complete nerd like me you probably ignored the hot girls and wondered: “How did they know where I live?”. There are a few simple ways to do this. Today [...]]]></description>
			<content:encoded><![CDATA[<p>Every wonder how all of those dating ads know that you are looking for hot girls near (insert your city here)? Well if you are a complete nerd like me you probably ignored the hot girls and wondered: “How did they know where I live?”. There are a few simple ways to do this. Today I am going to show you how to GeoCode using MaxMind&#8217;s free version.</p>
<p>MaxMind offers a paid version of this script that probably offers much more functionality. For what I need though, the free database does the job. I checked the results via a few proxies and they matched the US city fine. I am not sure how this works with international visitors, but I use it for US targeted traffic (It does pick up Canadian cities and Provinces fine….eh)..</p>
<p>First off you are going to need to download the Database and PHP API code:</p>
<p><a href="http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz">MaxMind GeoLiteCity</a><br />
<a href=" http://geolite.maxmind.com/download/geoip/api/php/geoip.inc">Geoip.inc</a><br />
<a href=" http://geolite.maxmind.com/download/geoip/api/php/geoipcity.inc">Geoipcity.php</a><br />
<a href="http://geolite.maxmind.com/download/geoip/api/php/geoipregionvars.php">Geoipregionvars.php</a></p>
<p>Once you download all of the files. Extract them all and upload them to the same folder on your server.</p>
<p>Now to use the API we need to include a few files. Then we are going to open the database and check the users location:</p>
<pre class="brush: php;">
include(&quot;geoip.inc&quot;);
include(&quot;geoipcity.inc&quot;);
include(&quot;geoipregionvars.php&quot;);
$gi = geoip_open(&quot;./GeoLiteCity.dat&quot;, GEOIP_STANDARD);
$rsGeoData = geoip_record_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);
</pre>
<p>This will grab the information, but what can we do with it. To find out what variables you can use print out the array:</p>
<pre class="brush: php;">
include(&quot;geoip.inc&quot;);
include(&quot;geoipcity.inc&quot;);
include(&quot;geoipregionvars.php&quot;);
$gi = geoip_open(&quot;./GeoLiteCity.dat&quot;, GEOIP_STANDARD);
$rsGeoData = geoip_record_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);

print &quot;&lt;pre&gt;&quot;;
print_r($rsGeoData);
print &quot;&lt;/pre&gt;&quot;;
</pre>
<p>The results should output something like this:</p>
<pre>
geoiprecord Object
(
    [country_code] => US
    [country_code3] => USA
    [country_name] => United States
    [region] => TN
    [city] => Memphis
    [postal_code] =>
    [latitude] => 35.1242
    [longitude] => -89.9521
    [area_code] => 901
    [dma_code] => 640
)
</pre>
<p>I ran the above code using a Memphis based proxy. As you can see MaxMinds database gives us:<br />
Country Abbreviation in two formats,<br />
Full country name,<br />
Region (state/province),<br />
City,<br />
Postal code (this usually works but is blank in the example),<br />
Latitude,<br />
Longitude,<br />
Area Code,<br />
DMA code (Designated Market Area as in Nielsen Media tv/radio market areas in the US)</p>
<p>Ok so now that we know what everything is, all we have to do is echo the results in the proper places. For example:</p>
<pre class="brush: php;">
echo $rsGeoData-&gt;city;
echo ' ,';
echo $rsGeoData-&gt;region;
</pre>
<p>Would out put:  Memphis, TN.<br />
So if you were going to use this in a template you would use something like this in the header:</p>
<pre class="brush: php;">
&lt;?php
include(&quot;geoip.inc&quot;);
include(&quot;geoipcity.inc&quot;);
include(&quot;geoipregionvars.php&quot;);
$gi = geoip_open(&quot;./GeoLiteCity.dat&quot;, GEOIP_STANDARD);
$rsGeoData = geoip_record_by_addr($gi, $_SERVER['REMOTE_ADDR']);
geoip_close($gi);

$location =  $rsGeoData-&gt;city.','.$rsGeoData-&gt;region;

?&gt;
</pre>
<p>Then in your template wherever you want the City, State to display simple:</p>
<pre class="brush: html;">

&lt;h1&gt;Meet girls near &lt;?php echo $location;?&gt;&lt;/h1&gt;
</pre>
<p>The your site might look something like this:<br />
<img src="http://teamtutorials.com/wp-content/uploads/2009/02/phpgeocoding.jpg" alt="php geo coding" title="php geo coding" width="532" height="169" class="alignnone size-full wp-image-1768" /></p>
<h3>Related Posts</h3>
<ul class="related_post">
<li>June 18, 2009 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/how-to-parse-a-csv-file-using-php" title="How to Parse a CSV File Using PHP">How to Parse a CSV File Using PHP (1)</a></li>
<li>March 30, 2009 &#8212; <a href="http://teamtutorials.com/other-tutorials/how-to-return-mysql-results-to-a-table" title="How to Return MySQL Results to a Table">How to Return MySQL Results to a Table (4)</a></li>
<li>March 13, 2009 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/editing-mysql-data-using-php" title="Editing MySQL Data Using PHP">Editing MySQL Data Using PHP (17)</a></li>
<li>September 21, 2008 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/creating-checkboxes-based-on-sql-results" title="Creating Checkboxes Based on SQL Results">Creating Checkboxes Based on SQL Results (3)</a></li>
<li>August 25, 2008 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/simple-php-website-templates" title="Simple PHP Website Templates">Simple PHP Website Templates (8)</a></li>
</ul>
<img src="http://teamtutorials.com/?ak_action=api_record_view&id=1767&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://teamtutorials.com/web-development-tutorials/how-to-get-a-users-geo-location/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Convert a MySQL date field using PHP Functions</title>
		<link>http://teamtutorials.com/web-development-tutorials/convert-a-mysql-date-field-using-php-functions</link>
		<comments>http://teamtutorials.com/web-development-tutorials/convert-a-mysql-date-field-using-php-functions#comments</comments>
		<pubDate>Fri, 20 Feb 2009 06:52:04 +0000</pubDate>
		<dc:creator>John Ward</dc:creator>
				<category><![CDATA[Database Tutorials]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Development Tutorials]]></category>

		<guid isPermaLink="false">http://teamtutorials.com/?p=1752</guid>
		<description><![CDATA[Today I am going to show you how to convert data returned from a MySQL database that was store as a date data type into a user friendly format. To do this you can take two different approaches. One way to do it is to use the function date_format() function in your query. The other way to to modify the date after it is returned.]]></description>
			<content:encoded><![CDATA[<p>Today I am going to show you how to convert data returned from a MySQL database that was store as a date data type into a user friendly format. To do this you can take two different approaches. One way to do it is to use the function date_format() function in your query. The other way to to modify the date after it is returned.</p>
<p>Since you are trying to convert the date I am assuming you can connect to a database, runa  query, and display the results. If not check out some of our older tutorials:</p>
<h2><a href="http://teamtutorials.com/web-development-tutorials/how-to-access-a-mysql-database-using-php">How to Access a MySQL Database Using PHP</a></h2>
<h2><a href="http://teamtutorials.com/web-development-tutorials/php-tutorials/inserting-data-into-a-mysql-database-using-php">Creating a Form that will Search a MySQL Database</a></h2>
<p>You can use the function in the query to convert the date or after the results are returned.</p>
<p>Using date_format() </p>
<p>Here is an example of how to call the function in a query:</p>
<pre class="brush: php;">
$query = mysql_query(&quot;select * date_format(date, '%b %d') as newdate from `table`&quot;)
</pre>
<p>Then when your results are returned simple echo $row[newdate]. The date I used will output the date in this format: Feb 18th (abbreviated month and numeric day with suffix).<br />
You need to pass the date string and the format mask to the function: date_format($date, $format)</p>
<p>You can pretty much do this the same way after your results are returned.<br />
For example:</p>
<pre class="brush: php;">
	$query = mysql_query(&quot;select * from `table` &quot;);
	while ($row = mysql_fetch_array($query)){
		$newdate = date_format(strtotime($row[date]), '%b %d');
	}
</pre>
<p>strtotime will convert a string date to a time stamp.</p>
<p>Other formatting option for date_format()</p>
<table style="border: 1px #ccc solid;padding:1px;">
<tr>
<th style="border: 1px #ccc solid;background:#39f">Specifier</th>
<th style="border: 1px #ccc solid;background:#39F">Description</th>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%a</td>
<td style="border: 1px #ccc solid;">Abbreviated weekday name (Sun..Sat)</td>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%b</td>
<td style="border: 1px #ccc solid;">Abbreviated month name (Jan..Dec)</td>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%c</td>
<td style="border: 1px #ccc solid;">Month, numeric (0..12)</td>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%D</td>
<td style="border: 1px #ccc solid;">Day of the month with English suffix (0th, 1st, 2nd, 3rd, …)</td>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%d</td>
<td style="border: 1px #ccc solid;">Day of the month, numeric (00..31)</td>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%e</td>
<td style="border: 1px #ccc solid;">Day of the month, numeric (0..31)</td>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%f</td>
<td style="border: 1px #ccc solid;">Microseconds (000000..999999)</td>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%H</td>
<td style="border: 1px #ccc solid;">Hour (00..23)</td>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%h</td>
<td style="border: 1px #ccc solid;">Hour (01..12)</td>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%I</td>
<td style="border: 1px #ccc solid;">Hour (01..12)</td>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%i</td>
<td style="border: 1px #ccc solid;">Minutes, numeric (00..59)</td>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%j</td>
<td style="border: 1px #ccc solid;">Day of year (001..366)</td>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%k</td>
<td style="border: 1px #ccc solid;">Hour (0..23)</td>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%l</td>
<td style="border: 1px #ccc solid;">Hour (1..12)</td>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%M</td>
<td style="border: 1px #ccc solid;">Month name (January..December)</td>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%m</td>
<td style="border: 1px #ccc solid;">Month, numeric (00..12)</td>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%p</td>
<td style="border: 1px #ccc solid;">AM or PM</td>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%r</td>
<td style="border: 1px #ccc solid;">Time, 12-hour (hh:mm:ss followed by AM or PM)</td>
</tr>
<tr>
<td style="border: 1px #ccc solid;">%S</td>
<td style="border: 1px #ccc solid;">Seconds (00..59)</td>
</tr>
</table>
<p>edit:<br />
This can also be done using the date function. Something like:</p>
<p>		$day = date(&#8221;d&#8221;,strtotime($row['date']));<br />
		$month = date(&#8221;M&#8221;,strtotime($row['date']));</p>
<p>would give you Mar 03</p>
<h3>Other Related Tutorials</h3>
<ul class="related_post">
<li>March 20, 2008 &#8212; <a href="http://teamtutorials.com/photoshop-tutorials/horizontal-menu-%e2%80%93-from-photoshop-to-the-web" title="Horizontal Menu – From Photoshop to the Web">Horizontal Menu – From Photoshop to the Web (10)</a></li>
<li>September 6, 2007 &#8212; <a href="http://teamtutorials.com/windows-tutorials/make-an-invisble-folder-on-the-desktop" title="Make an invisible folder on the desktop.">Make an invisible folder on the desktop. (7)</a></li>
<li>February 25, 2008 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/alternating-table-row-color-with-css-classes" title="Alternating Table Row Color With CSS Classes">Alternating Table Row Color With CSS Classes (3)</a></li>
<li>May 29, 2007 &#8212; <a href="http://teamtutorials.com/windows-tutorials/how-to-add-users-in-windows-vista" title="How to Add Users in Windows Vista">How to Add Users in Windows Vista (4)</a></li>
<li>September 25, 2007 &#8212; <a href="http://teamtutorials.com/windows-tutorials/eliminating-viruses-with-avg-free-edition" title="Eliminating Viruses with AVG Free Edition">Eliminating Viruses with AVG Free Edition (5)</a></li>
</ul>
<img src="http://teamtutorials.com/?ak_action=api_record_view&id=1752&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://teamtutorials.com/web-development-tutorials/convert-a-mysql-date-field-using-php-functions/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Configuring Authentication on MS SQL 2008</title>
		<link>http://teamtutorials.com/database-tutorials/configuring-authentication-on-ms-sql-2008</link>
		<comments>http://teamtutorials.com/database-tutorials/configuring-authentication-on-ms-sql-2008#comments</comments>
		<pubDate>Sat, 22 Nov 2008 09:59:51 +0000</pubDate>
		<dc:creator>Mike Maguire</dc:creator>
				<category><![CDATA[Database Tutorials]]></category>
		<category><![CDATA[Microsoft SQL 2008]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[express edition]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://teamtutorials.com/?p=1732</guid>
		<description><![CDATA[This tutorial will walk you through configuring your SQL server with credentials for applications and users to connect with. This will allow you to determine who has what type of access as well as how they can update the tables in the database. ]]></description>
			<content:encoded><![CDATA[<p>This tutorial will walk you through configuring you server with credentials for applications and users to connect with. This will allow you to determine who has what type of access as well as how they can update the tables in the database. </p>
<p>	First you need to decide which method you are going to use to give users access to the database. The first (and slightly less secure way) is to create an actual login for each person going to use the database. This will require you to get the users credentials in a form before attempting a connection to the database. The alternative to this method is to create only on login for a specific application and then create a table with an encrypted field for the password for the users. Then when the application connects to the database (using the credentials you created every time), it will look into a table to see if the credentials the user supplied are correct. I will walk you though both methods in this tutorial. Both steps require you to start from the beginning. Let’s get started.</p>
<p>First let’s open our Microsoft SQL Server Management Studio by going to Start->Programs->Microsoft SQL Server 2008->Microsoft SQL Server Management Studio.</p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_01.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_01.jpg" alt="" title="configuring_authentication_for_mssql_2008_01" width="337" height="336" class="alignnone size-medium wp-image-1733" /></a></p>
<p>Once in, you should see a pane to the left of the window that looks like the above image. Expand the Security group.</p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_02.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_02.jpg" alt="" title="configuring_authentication_for_mssql_2008_02" width="337" height="336" class="alignnone size-medium wp-image-1735" /></a></p>
<p>You screen should now look like above.</p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_03.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_03.jpg" alt="" title="configuring_authentication_for_mssql_2008_03" width="334" height="332" class="alignnone size-medium wp-image-1736" /></a></p>
<p>Right-click on the logins group and select new login. </p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_04.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_04.jpg" alt="" title="configuring_authentication_for_mssql_2008_04" width="700" height="628" class="alignnone size-medium wp-image-1737" /></a></p>
<p>You will then be presented the above screen. This is the screen we will use to configure the user to have access to the database.</p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_05.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_05.jpg" alt="" title="configuring_authentication_for_mssql_2008_05" width="700" height="628" class="alignnone size-medium wp-image-1738" /></a></p>
<p>Fill in the login name with what you want the username to be. If you are using the table method for authenticating, it is common practice to name this something like “appname_login” where appname is the name of your application that is connecting to it. Select the SQL Server Authentication radial button. Now you need to type in the password you want that user to start out with in the boxes provided twice. Then select whether they will be forced to adhere to password policies (change x amount of days, certain length, certain types of text, ect…), and password expirations. Also check the box if you want the user to have to change there password the next time they log-on. Finally select the default database (which in this case is TT) and select the default language. </p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_06.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_06.jpg" alt="" title="configuring_authentication_for_mssql_2008_06" width="700" height="628" class="alignnone size-medium wp-image-1739" /></a></p>
<p>Now, in the left pane, click on User Mapping and check the box for the database we want the user to have access to and then select the access type from the bottom window on the right that you want them to have.</p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_07.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_07.jpg" alt="" title="configuring_authentication_for_mssql_2008_07" width="337" height="336" class="alignnone size-medium wp-image-1740" /></a></p>
<p>Now if you expand the Login directory you will see the user we just created. The user will also appear listed under the users group that is under the security group of TT since we mapped his credentials to that database. Simply do this for each user that you want to have access to the database if you are using the login for each user method. If you do not want to use the table method, you can discontinue reading here as the remaining steps will be fore creating a table for credentials and how to set it up.  There are two ways to create a table, you can do it in the Graphical Interface, or you can write the script yourself. What I would recommend if you are new to SQL is to create it in the graphical interface and then view the code that it creates so that you can get an understanding of what the commands and syntax of SQL are. Let’s do it in the graphical interface:</p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_08.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_08.jpg" alt="" title="configuring_authentication_for_mssql_2008_08" width="553" height="494" class="alignnone size-medium wp-image-1741" /></a></p>
<p>Expand the databases collection, and then expand your database that you created. Once you do that right click on the table collections and select New Table…</p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_09.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_09.jpg" alt="" title="configuring_authentication_for_mssql_2008_09" width="139" height="316" class="alignnone size-medium wp-image-1742" /></a></p>
<p>Once the information loads, you will see a properties window to the right that will allow you to name the table. Name it something like ‘Users’ or ‘Credentials’. Once you do that we need to fill out the information for the table.</p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_10.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_10.jpg" alt="" title="configuring_authentication_for_mssql_2008_10" width="368" height="127" class="alignnone size-medium wp-image-1743" /></a></p>
<p>To create the info just begin typing in the appropriate box. Once you insert information into the box and move to the next field, the builder will auto-create the next line(column for the table). Make three columns to match what I have above. This will allow us to store the username, password, as role as a role for the user. This will allow us to use this field in our application to determine what the users can and can’t do easier. Also note that I have made the length of the password 255 characters. This is because I intend to encrypt the password that goes into this field which will take up more characters than required. I will cover this in a future tutorial.</p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_11.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_11.jpg" alt="" title="configuring_authentication_for_mssql_2008_11" width="406" height="346" class="alignnone size-medium wp-image-1744" /></a></p>
<p>Now that we have finished making our changes we can save the table but first let’s take a look at the code that this is going to generate. Right-click anywhere on the editor window and a menu will pop-up allowing you to select ‘Generate Change Script…’. </p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_12.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_12.jpg" alt="" title="configuring_authentication_for_mssql_2008_12" width="455" height="372" class="alignnone size-medium wp-image-1745" /></a></p>
<p>Once you select that menu option, the above window will appear with the script that the system would run to create the table. Look over it and try to understand what they do. Look the commands up in the help file and Google them to see what they do. This will be a good way to understand the commands. You can copy and paste this information into an SQL file and run it to create the table. Click on No to close the window once you are done and you will be taken back to the original screen. </p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_13.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_13.jpg" alt="" title="configuring_authentication_for_mssql_2008_13" width="382" height="160" class="alignnone size-medium wp-image-1746" /></a></p>
<p>Once you have everything in the table we will need, we can right-click on the tab for the editor and select save. This will save the table to our database.</p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_14.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_14.jpg" alt="" title="configuring_authentication_for_mssql_2008_14" width="266" height="338" class="alignnone size-medium wp-image-1747" /></a></p>
<p>Once the file finishes saving you should see it in the tables folder if you expand it’s view as above.</p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_15.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_15.jpg" alt="" title="configuring_authentication_for_mssql_2008_15" width="267" height="412" class="alignnone size-medium wp-image-1748" /></a></p>
<p>Now we need to insert some info into the table. Right-click on our database and select New Query as pictured above.</p>
<p>The query to insert people in this table will be as follows: -Note- It is good practice to capitalize all SQL command and tables so that you get differentiate the text easily.</p>
<pre class="brush: sql;">
INSERT INTO DBName..TableName VALUES(‘UserName’,’Password’,’Role’)
</pre>
<p>For example, if I wanted to create a user in the table for me with the password of password123 and the role of Admin the query would look like this:</p>
<pre class="brush: sql;">
INSERT INTO TT..USERS VALUES('MMaguire','password123','Admin')
</pre>
<p>Type your query into the text box and click on the green play button on the top portion of the screen to run the query.</p>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_16.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_16.jpg" alt="" title="configuring_authentication_for_mssql_2008_16" width="360" height="223" class="alignnone size-medium wp-image-1749" /></a></p>
<p>You should see this message if your query has been successfully ran. If not, please check your query for mistakes. Now we can do a select statement on the table to see our user that we just inserted.</p>
<pre class="brush: sql;">
SELECT * FROM TT..USERS
</pre>
<p><a href="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_17.jpg"><img src="http://teamtutorials.com/wp-content/uploads/2008/11/configuring_authentication_for_mssql_2008_17.jpg" alt="" title="configuring_authentication_for_mssql_2008_17" width="275" height="203" class="alignnone size-medium wp-image-1734" /></a></p>
<p>Once you run the select statement, the screen in the middle will show you the results returned as above. You can now do the above steps for each user (inserting them with the query). Once you do that your table is completed. This will conclude this tutorial. Next, we will look at using Visual Basic to call this table and verify a user has permissions.</p>
<h3>Related Posts</h3>
<ul class="related_post">
<li>November 10, 2008 &#8212; <a href="http://teamtutorials.com/database-tutorials/configuring-and-creating-a-database-in-ms-sql-2008" title="Configuring and Creating a Database in MS SQL 2008">Configuring and Creating a Database in MS SQL 2008 (8)</a></li>
<li>November 9, 2008 &#8212; <a href="http://teamtutorials.com/windows-tutorials/installing-microsoft-sql-2008-express-edition" title="Installing Microsoft SQL 2008 Express Edition">Installing Microsoft SQL 2008 Express Edition (4)</a></li>
<li>July 16, 2008 &#8212; <a href="http://teamtutorials.com/web-development-tutorials/php-tutorials/creating-a-form-that-will-search-a-mysql-database" title="Creating a Form that will Search a MySQL Database">Creating a Form that will Search a MySQL Database (32)</a></li>
</ul>
<img src="http://teamtutorials.com/?ak_action=api_record_view&id=1732&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://teamtutorials.com/database-tutorials/configuring-authentication-on-ms-sql-2008/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
