This Tutorial will run you through the basics of building your own Tutorial CMS!
We are going to use these variables for our MySQL database.
- ID
- title
- avatar
- date
- description
- user
- message
1. Lets start off by creating our table..Go to your database, as I asume you already know how to create, and import this SQL.
| CREATE TABLE 'tutorials' ( 'ID' tinyint(11) NOT NULL auto_increment, 'title' text NOT NULL, 'avatar' text NOT NULL, 'date' date NOT NULL default '0000-00-00', 'description' text NOT NULL, 'user' text NOT NULL, 'message' text NOT NULL, PRIMARY KEY ('ID') ) TYPE=MyISAM AUTO_INCREMENT=1 ; |
2. Now, we're going to enter in our tutorial into our table. In PHPmyAdmin (or whatever you use) insert a new row into your table, which we named tutorials. You dont need to add anything for the ID, it automatically increases the ID number by 1.
After you finished entering in your tutorial into the MySQL database, create a new file, using Dreamweaver or whatever you use. We will call it dbconnect.php.
Copy and paste this into your file...With of course adding in your information
| <? $username = "yourusername"; $password = "yourpassword"; $host = "localhost"; $database = "yourdatabase"; mysql_connect($host,$username,$password) or die("Error connecting to Database! " . mysql_error()); mysql_select_db($database) or die("Cannot select database! " . mysql_error()); ?> |
3. Now create a new file, in the same directory as the dbconnect.php file. Call it tutorials.php and put this in the file.. of course you may have to change it to fit your needs...
| <?php include ("dbconnect.php"); if (isset($ID)) { $tuts="SELECT * from yourtable where ID='$ID'"; $tuts2=mysql_query($tuts); while ($tuts3=mysql_fetch_array($tuts2)) { echo " <table width=100% border=0 cellspacing=3 cellpadding=0> <tr> <td> <font color=#82A1FF size=1 face=Verdana, Arial, Helvetica, sans-serif><b>$tuts3[title]</b><br> <font color=#000000>By <b>$tuts3[user]</b><br> <i>$tuts3[description]</i><br> <br> $tuts3[message]<br> <br> </td> </tr> </table> "; } } else if(!isset($id)) { $tut="SELECT * from yourtable"; $tut2=mysql_query($tut); while($tut3=mysql_fetch_array($tut2)) { echo " <font color=#000000 size=1 face=Verdana, Arial, Helvetica, sans-serif> <table width=250 border=0 cellspacing=3 cellpadding=0> <tr> <td width=42 height=42> <div align=center><a href='tutorials.php?ID=$tut3[ID]'><img src='$tut3[avatar]' border='0' alt='$tut3[title]' target='main'></a></div></td> <td width=208><font color=#82A1FF size=1 face=Verdana, Arial, Helvetica, sans-serif><strong>$tut3[title]</strong><br> <font color=#000000><em>$tut3[date]</em><br> By <strong>$tut3[user]</strong></font><br></font></td> </tr></table> "; } } ?> |
4. Now, to create an add form.. create a new file called add.php and put this in it..
| <form action="verify.php" method=post> <p>Title:<br> <input type="text" name="frmtitle" size="23" value="Title"> <br> Avatar URL :<br /> <input type="text" name="frmavatar" size="23" value="Icon URL"> <br /> User:<br> <input type="text" name="frmuser" size="23" value="Username"> <br> Description:<br> <input type="text" name="frmuser" size="23" value=""> <br> Message: <br> <textarea name="frmmessage" cols="100" rows="25"></textarea> <br> <input type="submit" name="Submit" value="Submit"> </p> </form> |
5. Now, to make a verify file to put the new information in the MySQL database. Create a new file called verify.php and add this in it..
| <?php // Include the config include("dbconnect.php"); // Set the variables from the form $Title = $_POST['frmtitle']; $Avatar = $_POST['frmavatar']; $User = $_POST['frmuser']; $Message = $_POST['frmmessage']; $Description = $_POST['frmdescription']; $sql = "INSERT INTO $table SET title='$Title', avatar='$Avatar', user='$User', message='$Message', description='$Description'"; if (mysql_query($sql)) { echo("Your tutoral has been added<br />"); } else { echo("Error adding entry: " . mysql_error() . ""); } ?> <script language=javascript> <!-- location.href="tutorials.php"; //--> </script> |
6. And your done! This tutorial was made from several other tutorials, but with major editing and addons. Soon to add on an edit forum and delete form and possible a pagination addon.. if I can figure it ouit!
Related Articles
- PHP/MySQL Tutorial SystemThis Tutorial will run you through the basics of building your own Tutorial CMS!
- Acquiring PHP MySQLPHP and MySQL are already packaged in Linux and Mac OS X OSs. However, most PHP developer are actually using Windows when developing PHP applications. This is also true to myself. I have Mandrake Linux 10 but Ill just use it for testing purposes of my finished scripts...
- Alternating Rows: MysqlThe first thing we need to do is connect to the database. I always put my db connection in a universal file, that way I can just change the variables once if I need to; but for the sake of the tutorial, im putting it in this file.
- PHP User StatsIn this tutorial I am going to teach you how to make a User Stats menu in PHP and MySQL which displays: Unique hits, Unique hits today, Total hits, Total hits today. If you dont have MySQL you can get one for free here.
- PHP Navigation and Connecting to a MySQL DatabasePHP Navigation and Connecting to a MySQL Database
- Design an Online Chat Room with PHP and MySQLIn this article, you will learn how to design and develop a simple online chat room with PHP and MySQL. This tutorial explains every steps of the development, including both database design and PHP programming. Basic computer skills and knowledge of HTML and PHP are required. Ok, lets begin now. ....
- Alternating Rows: ArraysThe first thing we do here is echo out the html, again I wont go over this because theres really nothing to explain, except the css. We have two css classes, one for each of the alternating rows.
- Create a Contact Page with HTML and PHPI have made a tutorial about how to install EasyPhp and now i come with an example. Today we learn how to create a Contact Page in HTML and PHP very easy! Download the next files to exercise on them:
- Register Login ScriptThe following tutorial will teach you how to add a login/register script to your site. This tutorial requires 6 files, and PHP with MySQL installed.
- Dynamic PHP Google SitemapThis tutorial will show You how to generate google sitemaps based on Your site MySQL structure.
