<?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>The Tutorial Blog &#187; mysql</title>
	<atom:link href="http://www.thetutorialblog.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thetutorialblog.com</link>
	<description></description>
	<lastBuildDate>Tue, 08 Nov 2011 19:21:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<image>
<link>http://www.thetutorialblog.com</link>
<url>http://www.thetutorialblog.com/wp-content/plugins/maxblogpress-favicon/icons/favicon-28.ico</url>
<title>The Tutorial Blog</title>
</image>
		<item>
		<title>Creating a WordPress plugin</title>
		<link>http://www.thetutorialblog.com/php/creating-a-wordpress-plugin/</link>
		<comments>http://www.thetutorialblog.com/php/creating-a-wordpress-plugin/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 17:10:34 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Text Tutorials]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[makeuseof]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[wp]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=38</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	The plugin that I'm going to show you how to create within this post is a plugin that I created for MakeUseOf. Creating plugins for WP is relatively easy and uses actions to call functions that are included in pages within the main WP files. To learn more about creating plugins for WP go here. [...]


Related posts:<ol><li><a href='http://www.thetutorialblog.com/cocoa-objective-c/creating-a-basic-ipad-application/' rel='bookmark' title='Permanent Link: Creating a basic iPad application'>Creating a basic iPad application</a> <small>Because of the recent announcement of the iPad 2 more...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fcreating-a-wordpress-plugin%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fcreating-a-wordpress-plugin%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="Creating a Wordpress plugin" alt=" Creating a Wordpress plugin" /><br />
			</a>
		</div>
<p>The plugin that I'm going to show you how to create within this post is a plugin that I created for <a href="http://www.makeuseof.com" target="_blank">MakeUseOf</a>.</p>
<p>Creating plugins for WP is relatively easy and uses actions to call functions that are included in pages within the main WP files. To learn more about creating plugins for WP go <a href="http://codex.wordpress.org/Main_Page" target="_blank">here</a>.</p>
<p>Ok so lets get started with creating the plugin.</p>
<p>When creating a plugin for WP make sure that you include your own unique word or acronym to your functions so that they don't conflict with any other plugins that may be installed.</p>
<p>Because I created this for MakeUseOf the acronym I use is MUO and then AF because I named the plugin author footer so every function within this plugin begins with MUO_AF.<br />
<span id="more-38"></span><br />
So to start our plugin we add this<br />
<div id="code_div">&lt;?php<br />
/*<br />
Plugin Name: MUO Author Footer<br />
Description: Authors type in the footer that will be attached to the end of their articles with modifications<br />
Author: Wez<br />
Version: 1.0<br />
*/<br />
</div></p>
<p>Here is where we add the name of our plugin, a description, your name and the version number of your plugin.</p>
<p>The next bit of code that we add is the <em>register_activation_hook</em> and <em>register_deactivation_hook</em> so that when the plugin is activated and deactivated the code within functions that we will create in our next step will be executed.<br />
<div id="code_div">register_activation_hook(__FILE__, 'MUO_AF_activate');<br />
register_deactivation_hook(__FILE__, 'MUO_AF_deactivate');</div></p>
<p>We're now going to create two functions called MUO_AF_activate and MUO_AF_deactivate so that the register hooks work correctly.<br />
<div id="code_div">function MUO_AF_activate() {<br />
	$query = mysql_query("CREATE TABLE `muo_author_footer` (<br />
	  `author_id` int(11) NOT NULL,<br />
	  `author_name` varchar(50) NOT NULL,<br />
	  `author_signature` text NOT NULL,<br />
	  PRIMARY KEY  (`author_id`)<br />
	) ENGINE=MyISAM DEFAULT CHARSET=latin1;");<br />
}</p>
<p>function MUO_AF_deactivate(){<br />
	$query = mysql_query("DROP TABLE `muo_author_footer`");<br />
}</div><br />
What this code does is when the plugin is activated it will create a table within the MySQL database that the plugin will use to store and retrieve information. When the plugin is deactivated it will delete the table that was created in the database.</p>
<p>In the next step we will write code that will be called and displayed within the Your Profile page in the admin-cp.<br />
<div id="code_div">function MUO_AF_profile() {<br />
	global $userdata;<br />
	get_currentuserinfo();<br />
	$query = mysql_query("SELECT * FROM muo_author_footer WHERE author_id='$userdata->ID'");<br />
	$row = mysql_fetch_array($query);<br />
	$author_signature = $row['author_signature'];<br />
	echo '&lt;table class="form-table"><br />
	&lt;tr>&lt;th>Author Post Signature</th>
<p>	&lt;td>&lt;p><br />
	&lt;textarea name="MUO_Author_Sig" cols="30" rows="5">'.$author_signature.'&lt;/textarea><br />
	&lt;/p><br />
	&lt;h2>Preview:&lt;/h2>&lt;p>&lt;em>';<br />
	echo $author_signature;<br />
	echo '&lt;/em>&lt;/p><br />
	&lt;/td>&lt;/tr><br />
	&lt;/table>';<br />
}</div></p>
<p>When the Update Profile button is clicked the information from the previous bit of code will be retrieved in the next bit of code and the database will be updated.<br />
<div id="code_div">function MUO_AF_edit(){<br />
	global $userdata, $current_user;<br />
	get_currentuserinfo();</p>
<p>	$MUO_Author_Sig = $_POST['MUO_Author_Sig'];</p>
<p>	$query = mysql_query("SELECT * FROM muo_author_footer WHERE author_id='$userdata->ID'");</p>
<p>	if( mysql_num_rows($query) > 0 ) {<br />
		$query = mysql_query("UPDATE muo_author_footer SET author_signature='$MUO_Author_Sig' WHERE author_id='$userdata->ID'");<br />
	} else {<br />
		$query = mysql_query("INSERT INTO muo_author_footer VALUES ('$userdata->ID','$userdata->user_login','$MUO_Author_Sig')");<br />
	}</p>
<p>}</div></p>
<p>The code we will write now is the code that will grab the contents of the post and then attach the authors signature to the end of that post.<br />
<div id="code_div">function MUO_AF_publish_post( $content ) {<br />
	global $wpdb;<br />
	$num = 0;<br />
	if (get_the_ID() > $num) {<br />
		$the_author_id = get_the_author_id();<br />
		$author_query = mysql_query("SELECT * FROM muo_author_footer WHERE author_id='". $the_author_id ."'");<br />
		$author_row = mysql_fetch_array($author_query);<br />
		$author_signature = $author_row['author_signature'];</p>
<p>		$content .= '&lt;style><br />
					.muo_af_style { background-color: #B4D0E1; border: 2px solid #4275B8; }<br />
					&lt;/style>';</p>
<p>		if(strstr($author_signature, 'by') == false) :</p>
<p>		$content .= '&lt;p class="muo_af_style">&lt;em>(By) '.$author_signature.'&lt;/em>&lt;/p>';</p>
<p>		else :</p>
<p>		$content .= '&lt;p class="muo_af_style">&lt;em>'.$author_signature.'&lt;/em>&lt;/p>';</p>
<p>		endif;</p>
<p>		return $content;<br />
	}<br />
	else {<br />
		return $content;<br />
	}<br />
}</div></p>
<p>We will now add the functions to actions, this is the most important part of the code because without this none of the functions would be called and nothing would happen.<br />
<div id="code_div">add_action('show_user_profile', 'MUO_AF_profile');<br />
add_filter('profile_update', 'MUO_AF_edit');<br />
add_action('the_content', 'MUO_AF_publish_post');<br />
</div></p>
<p>Then at the end of the file close the php tags with<br />
<div id="code_div">?></div></p>
<p>I have not been very descriptive in this tutorial of what the actual code within the plugin is doing because I created this tutorial wanting to show people the basics bit of code that are needed to call functions and make a plugin work.</p>
<p>I hope that you have learnt something by reading this tutorial and feel free to post a comment with your thoughts on this post.</p>


<p>Related posts:<ol><li><a href='http://www.thetutorialblog.com/cocoa-objective-c/creating-a-basic-ipad-application/' rel='bookmark' title='Permanent Link: Creating a basic iPad application'>Creating a basic iPad application</a> <small>Because of the recent announcement of the iPad 2 more...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/php/creating-a-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>PHP News System Part 4</title>
		<link>http://www.thetutorialblog.com/php/php-news-system-part-4/</link>
		<comments>http://www.thetutorialblog.com/php/php-news-system-part-4/#comments</comments>
		<pubDate>Sun, 17 Aug 2008 23:15:05 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Text Tutorials]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[delete]]></category>
		<category><![CDATA[edit]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[news system]]></category>
		<category><![CDATA[part 4]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[remove]]></category>
		<category><![CDATA[thetutorialblog]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=34</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	If you haven't checked out the previous tutorials then click on the names to view them. Part 1, Part 2, Part3. In Part 4 of this tutorial you are going to learn how to edit and delete your posts from the admin page. Connect to the database The first thing that we need to do [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fphp-news-system-part-4%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fphp-news-system-part-4%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="PHP News System Part 4" alt=" PHP News System Part 4" /><br />
			</a>
		</div>
<p>If you haven't checked out the previous tutorials then click on the names to view them. <a href="http://www.thetutorialblog.com/2008/06/17/php-news-system-part-1-with-sound/">Part 1</a>, <a href="http://www.thetutorialblog.com/2008/07/30/php-news-system-part-2/">Part 2</a>, <a href="http://www.thetutorialblog.com/2008/08/01/php-news-system-part-3/">Part3</a>.</p>
<p>In Part 4 of this tutorial you are going to learn how to edit and delete your posts from the admin page.<br />
<span id="more-34"></span></p>
<h2>Connect to the database</h2>
<p>The first thing that we need to do is go to <strong>index.php</strong> under the admin folder and to the after the first <strong>&lt;?php </strong>add this:</p>
<p><div id="code_div">include("../dbconnect.php");</div></p>
<h2>Display The Posts</h2>
<p>After this line in index.php<br />
<div id="code_div">echo "&lt;a href="newpost.php">New Post&lt;/a>";</div></p>
<p>add below it<br />
<div id="code_div">echo "&lt;br>";<br />
		echo "&lt;br>";<br />
		echo "Edit Posts &lt;br>";</p>
<p>		$query = mysql_query("SELECT * FROM news_system ORDER BY id DESC");<br />
		while ( $row = mysql_fetch_array( $query ) ) {<br />
			$id = $row['id'];<br />
			$author = $row['author'];<br />
			$title = $row['title'];</p>
<p>			echo '&lt;a href="editpost.php?id='.$id.'">'.$title.' - By '.$author.'&lt;/a>&lt;br>';<br />
		}<br />
	}<br />
</div></p>
<p>What we're doing here is querying the database to display all the posts in the table <em>news_system</em> from the newest post to the oldest post. We then use a while loop to loop through and display each post. You will see that each post links to <strong>editpost.php</strong> so what we will do now is create an <strong>editpost.php</strong> file.</p>
<h2>Creating editpost.php</h2>
<p>After you have created your editpost.php file add the following code to it<br />
<div id="code_div">&lt;?php<br />
include("../dbconnect.php");</p>
<p>$id = $_GET['id'];</p>
<p>?></div></p>
<p>What we're doing here is opening the php tags then including <strong>dbconnect.php</strong> that connects to the database. <em>$_GET['id']</em> gets the id from the URL and stores it in a variable called <em>$id</em>. Then we close the php tags with <em>?></em>.</p>
<p>Before the <em>?></em> insert the following code.<br />
<div id="code_div">$query = mysql_query("SELECT * FROM news_system WHERE id='$id'");<br />
$row = mysql_fetch_array($query);</p>
<p>$author = $row['author'];<br />
$date = $row['date'];<br />
$title = $row['title'];<br />
$post = $row['post'];</div><br />
What this code will do is find the row in the table <em>news_system</em> with the id that is stored in $id. Then we retrieve the author, date, title and post information.</p>
<p>Below this we're going to create a html form and display the information that we have retrieved from the database within it so that we can edit it.</p>
<p><div id="code_div">if( !$_POST['submit'] ) {<br />
	echo '&lt;form method="POST">';<br />
	echo 'Author: &lt;input type="text" name="author" value="'.$author.'"> &lt;br>';<br />
	echo 'Date: &lt;input type="text" name="date" value="'.$date.'"> &lt;br>';<br />
	echo 'Title: &lt;input type="text" name="title" value="'.$title.'"> &lt;br>';<br />
	echo 'Post: &lt;br>&lt;textarea name="post" cols="30" rows="5">'.$post.'&#038;lt'/textarea>&lt;br>';<br />
	echo '&lt;input type="hidden" name="id" value="'.$id.'">';<br />
	echo '&lt;input type="submit" name="submit" value="Edit Post">&lt;br>&lt;br>';</p>
<p>	echo '&lt;a href="deletepost.php?id='.$id.'">Delete Post&lt;/a>';<br />
} </div></p>
<p>What happens in this piece of code is if the post hasn't been submitted then include the form. Within all the form elements you'll see that they all have <em>value</em> and that value is the variables. We also include the id in a hidden element so that we can carry it over for when the submit button is pressed. Under the submit button there is a link to a page that we will create in a minute that will delete that post.</p>
<p>In the next lot of code we're going to make it retrieve all of the values from the form and store them in variables that will then be used to update the row within the table.<br />
<div id="code_div">else {<br />
	$id = $_POST['id'];<br />
	$author = $_POST['post'];<br />
	$date = $_POST['date'];<br />
	$title = $_POST['title'];<br />
	$post = $_POST['post'];</p>
<p>	$query = mysql_query("UPDATE news_system SET author='$author', date='$date', title='$title', post='$post' WHERE id='$id'");<br />
	echo 'Post was updated, &lt;a href="index.php">return home</a>';<br />
}</div><br />
Here you can see we are retrieving all the information from the form and storing the information into variables. Then we query the database to update the new values and lastly return a message to the user to know that it has been updated.</p>
<p>All the code together should look like this:<br />
<div id="code_div"><br />
&lt;?php<br />
include("../dbconnect.php");</p>
<p>$id = $_GET['id'];</p>
<p>$query = mysql_query("SELECT * FROM news_system WHERE id='$id'");<br />
$row = mysql_fetch_array($query);</p>
<p>$author = $row['author'];<br />
$date = $row['date'];<br />
$title = $row['title'];<br />
$post = $row['post'];</p>
<p>if( !$_POST['submit'] ) {<br />
	echo '&lt;form method="POST">';<br />
	echo 'Author: &lt;input type="text" name="author" value="'.$author.'"> &lt;br>';<br />
	echo 'Date: &lt;input type="text" name="date" value="'.$date.'"> &lt;br>';<br />
	echo 'Title: &lt;input type="text" name="title" value="'.$title.'"> &lt;br>';<br />
	echo 'Post: &lt;br>&lt;textarea name="post" cols="30" rows="5">'.$post.'&#038;lt'/textarea>&lt;br>';<br />
	echo '&lt;input type="hidden" name="id" value="'.$id.'">';<br />
	echo '&lt;input type="submit" name="submit" value="Edit Post">&lt;br>&lt;br>';</p>
<p>	echo '&lt;a href="deletepost.php?id='.$id.'">Delete Post&lt;/a>';<br />
} </p>
<p>else {<br />
	$id = $_POST['id'];<br />
	$author = $_POST['post'];<br />
	$date = $_POST['date'];<br />
	$title = $_POST['title'];<br />
	$post = $_POST['post'];</p>
<p>	$query = mysql_query("UPDATE news_system SET author='$author', date='$date', title='$title', post='$post' WHERE id='$id'");<br />
	echo 'Post was updated, &lt;a href="index.php">return home</a>';<br />
}<br />
?><br />
</div></p>
<p>Now that we have created the <strong>editpost.php</strong> file its time to create <strong>deletepost.php</strong>.</p>
<h2>Delete a post</h2>
<p>In this delete file I haven't added any confirmation to ask the user if they're certain that they want to delete the post. It might be a good idea to add it using submit buttons or javascript.</p>
<p><div id="code_div">&lt;?php<br />
include("../dbconnect.php");<br />
$id = $_GET['id'];</p>
<p>$query = mysql_query("DELETE FROM news_system WHERE id='$id'");</p>
<p>echo 'The post was deleted, &lt;a href="index.php">return home&lt;/a>';<br />
?></div></p>
<p>As usual we include the php tag and the database file as we're going to be querying the database. We then get the id from the URL and store it in <em>$id</em>. Then we query the database and delete the post and last of all we display a message to the user saying the post has been deleted.</p>
<h2>Thank you</h2>
<p>Thanks for taking the time to read this tutorial. I hope that you have learnt something and that you keep returning to check out our latest tutorials.</p>
<p>If there is anything that you need help with then please post a comment and I'll write a tutorial on it or get back to you.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/php/php-news-system-part-4/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>PHP News System Part 2</title>
		<link>http://www.thetutorialblog.com/php/php-news-system-part-2/</link>
		<comments>http://www.thetutorialblog.com/php/php-news-system-part-2/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 00:52:48 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Text Tutorials]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[news system]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=28</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	If you haven't already seen part 1 of this tutorial then watch it here. For the second part of this tutorial you will learn how to create a cookie to log the admin user in and create the tables for your news system. Ok so first of all we are going to modify the file [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fphp-news-system-part-2%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fphp-news-system-part-2%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="PHP News System Part 2" alt=" PHP News System Part 2" /><br />
			</a>
		</div>
<p>If you haven't already seen part 1 of this tutorial then watch it <a href="http://www.thetutorialblog.com/2008/06/17/php-news-system-part-1-with-sound/">here</a>.</p>
<p>For the second part of this tutorial you will learn how to create a cookie to log the admin user in and create the tables for your news system.</p>
<p><span id="more-28"></span></p>
<p>Ok so first of all we are going to modify the file from the first tutorial.</p>
<p>Modify:</p>
<blockquote><p>if($_POST['username == $username AND $_POST['password'] == $password)<br />
{<br />
echo '&lt;a href="newpost.php"&gt;New Post&lt;/a&gt;';<br />
}</p></blockquote>
<p>To</p>
<blockquote><p>if($_POST['username == $username AND $_POST['password'] == $password)<br />
{<br />
setcookie("username", $username, time()+3600);<br />
setcookie("password", $password, time()+3600);<br />
echo '&lt;a href="newpost.php"&gt;New Post&lt;/a&gt;';<br />
}</p></blockquote>
<p>The two new bits of code that we add are <em>setcookie("username", $username, time()+3600);</em> and <em>setcookie("password", $password, time()+3600);</em>. What we are doing here is creating a cookie called username and assigning the value of $username to it and <em>time()+3600</em> will make the cookie expire in 1 hour.</p>
<h3><strong>Create the news table</strong></h3>
<p>Insert the following MySQL code into phpMyAdmin or any kind of MySQL software that you are using</p>
<blockquote><p>CREATE TABLE  `news_system` (<br />
 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,<br />
 `author` VARCHAR( 50 ) NOT NULL ,<br />
 `date` VARCHAR( 20 ) NOT NULL ,<br />
 `title` VARCHAR( 100 ) NOT NULL ,<br />
 `post` TEXT NOT NULL<br />
) ENGINE = MYISAM ;</p></blockquote>
<h3><strong>Connect To The Database</strong></h3>
<p>Create a file called dbconnect.php in the parent directory to the admin folder.</p>
<p>Enter the following code into dbconnect.php</p>
<blockquote><p>
&lt;?php<br />
$host = "localhost";<br />
$username = "username";<br />
$password = "password";<br />
$db = "news_system";</p>
<p>$conn = mysql_connect($host, $username, $password);<br />
mysql_select_db($db);<br />
?>
</p></blockquote>
<p>Change the variables $host, $username, $password and $db.<br />
Most of the time localhost is what the host will be so if you're unsure then don't change this.</p>
<h3><strong>Create News Submission Form</strong></h3>
<p>Create a file called newpost.php and insert the following code below into the newpost.php file.</p>
<h3><strong>Make the form</strong></h3>
<p>Now that are tables have been created in our database the next thing to do is to add a HTML form and PHP code to process the form.</p>
<p>Our HTML Form:</p>
<blockquote><p>&lt;form method="POST"&gt;<br />
Author: &lt;input type="text" name="author"&gt;&lt;br&gt;<br />
Title: &lt;input type="text" name="title"&gt;&lt;br&gt;<br />
Post:&lt;br&gt;<br />
&lt;textarea name="post" cols="30" rows="7"&gt; &lt;/textarea&gt;&lt;br&gt;<br />
&lt;input type="submit" name="submit" value="Publish Post"&gt;<br />
&lt;/form&gt;</p></blockquote>
<p>PHP Code:</p>
<blockquote><p>&lt;?php<br />
require("../dbconnect.php");<br />
//if submit button has been pressed<br />
if($_POST['submit']){<br />
//retrieve form text fields<br />
$author = $_POST['author'];<br />
$title = $_POST['title'];<br />
$post = $_POST['post'];</p>
<p>//get the date<br />
$date = date('d/m/Y');</p>
<p>//post information to database<br />
$query = mysql_query("INSERT INTO news_system VALUES('','$author','$date','$title','$post')");</p>
<p>if($query){<br />
echo "Post was successfully added to the database";<br />
}<br />
else {<br />
echo "Post was not added";<br />
}<br />
}</p>
<p>?&gt;</p></blockquote>
<p>
In the next post you will learn how to display the latest 5 posts.</p>
<p>If something isn't clear or you would like something to be included in the next post then please leave your comments.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/php/php-news-system-part-2/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>PHP and MySQL User Register Page</title>
		<link>http://www.thetutorialblog.com/php/php-and-mysql-user-register-page/</link>
		<comments>http://www.thetutorialblog.com/php/php-and-mysql-user-register-page/#comments</comments>
		<pubDate>Thu, 03 Apr 2008 17:12:44 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[macosx]]></category>
		<category><![CDATA[mamp]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[system]]></category>
		<category><![CDATA[textmate]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[user system]]></category>

		<guid isPermaLink="false">http://www.katocan.com/?p=11</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	A tutorial showing how to create a page which lets someone add a user to a database, its a little bit rushed and not well explained but I hope it helps in some way. I will add a better explained video tutorial soon on how to create a user system using PHP and MySQL. What [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fphp-and-mysql-user-register-page%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fphp-and-mysql-user-register-page%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="PHP and MySQL User Register Page" alt=" PHP and MySQL User Register Page" /><br />
			</a>
		</div>
<p>A tutorial showing how to create a page which lets someone add a user to a database, its a little bit rushed and not well explained but I hope it helps in some way. I will add a better explained video tutorial soon on how to create a user system using PHP and MySQL.</p>
<p><object width="480" height="392" data="http://flash.revver.com/player/1.0/player.swf?mediaId=787128&#038;affiliateId=42154" type="application/x-shockwave-flash" id="revvervideoa17743d6aebf486ece24053f35e1aa23"><param name="Movie" value="http://flash.revver.com/player/1.0/player.swf?mediaId=787128&#038;affiliateId=42154"></param><param name="FlashVars" value="allowFullScreen=true&#038;backColor=#000000&#038;frontColor=#ffffff&#038;gradColor=#000000"></param><param name="AllowFullScreen" value="true"></param><param name="AllowScriptAccess" value="always"></param><embed type="application/x-shockwave-flash" src="http://flash.revver.com/player/1.0/player.swf?mediaId=787128&#038;affiliateId=42154" pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always" flashvars="allowFullScreen=true&#038;backColor=#000000&#038;frontColor=#ffffff&#038;gradColor=#000000" allowfullscreen="true" width="480" height="392"></embed></object></p>
<p>What you will learn to do in this video tutorial is to create a basic HTML form which asks the user for their username and password, when the submit button is clicked their username and password will then be added to a MySQL database.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/php/php-and-mysql-user-register-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

