|
| Web Hosting Deals | Holiday Logo Design | Webcam Chat | Website Header Templates | Register domain | Search Engine Optimisation | Web Hosting |
|
|||||||
| PHP / Perl / Java / JavaScript / CGI Tutorials PHP / Perl / Java / JavaScript / CGI Tutorials Please do not use this Forum to advertise your site or to link to tutorials. |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
||||
|
The CMS (#1) PHP
Hi there all!
Hope you liked my previous tutorial on the baisics of PHP! If you havent read it, i suggest you do you can find it here Right then, as said in that tutorial we are going to start the first section of our news management/Content management system Now the thing you need to do here, and this is the first thing i am going to teach you, is how to plan ahead, so we are going to build our file structure right now, then we know where to put stuff! OK! So here is an image of what i have got: ![]() And that looks like this: ![]() Hokay, so if you create somthing like that when thats all fine and dandy! Right, in this tutorial we are going to be using 2 types of database. 1.) MySQL - An extremely fast, robust and safe back and database, all good hosting providers should provide you access to them. 2.) Flat file - This is baisicly a text file, such as a .txt extention, these are good, but are much less secure than MySQL so we may not use them at all, it depends if i feel you need to know them. __________________________________________________ _______________ Right so lets get on with MySQL **Note** You will see allot of the code i use taken from the following sites: tizag.com w3schools.com So don't post saying you "have seen the code before :O" because i know you will have, i do this because i like they way they lay out the code, and because they helped me get to the standard i am at today. **/Note** So as with all types of databases, we need to establish a connection to the database before we can do anything else. So onto creating our first file: this should go in the includes directory you will have created, and should be saved with a .php extension. This should be called "connect.php" PHP Code:
1.) // The MySQL info, edit these - This is a comment in PHP, just lets you remember what the code does, and will help you find and fix problems faster, and is generally very usefull. 2.) $host = "localhost"; - Remmeber back to my first tutorial when we declared some variables? well here is another one. This is baisicly the address of the server where your MySQL database is stored. Now i know that with my company you allways use localhost, because the MySQL server, is allways on the same server as apache. However if your using say a free host, then you will need to put the IP address of the server in here. 3.) $dbuser = "DB_USER"; - The user you are going to connect to the database with. 4.) $dbpass = "DB_PASS"; - The password to go with the user your connecting with 5.) $dbname = "DB_NAME"; - The name of the database your connecting too. 6.) mysql_connect("$host","$dbuser","$dbpass"); - The nitty gritty of the page, this is saying the following: "With the function mysql_connect with the variables $host $dbuser & $dbpass connect to the database." 7.) mysql_select_db("$dbname"); - This is saying With the function mysql_select_db select the database with the name the same as the variable $dbname So that is pretty simple code really. so i want you to copy that code into your file and edit the information to suit you. then save it with a .php extension! And there we go we have connected with the database! I am going to end this tutorial here, but the next one will be posted in a matter of hours. Thanks, and i hope you have learned somthing! Base (With all tutorials i will allways include a ZIP file containing all of the work i have done on the system so far, so you can check it against my code.)
__________________
http://www.pointserv.co.uk/gfx/deal_..._pointserv.png PointServ.co.uk - One of the UK's cheapest webhosting companies. |
|
|||
|
Very nice, I like this idea very much and I'm going to read all the parts, I think this would be great for people that are new to PHP.
It is good explained, maybe when you are a bit further you can put your progress online or something then people can see how it looks ![]() |
|
||||
|
Indeed, thanks for your comments.
The next tutorial is the layout of our CMS, is going to be quite long so will take some reading. Base
__________________
http://www.pointserv.co.uk/gfx/deal_..._pointserv.png PointServ.co.uk - One of the UK's cheapest webhosting companies. |
|
||||
|
connect problem
hey i got a problem when i did this
Code:
Parse error: parse error, unexpected '=' in /home/www/php.arabian-outlaw.com/includes/connect.php on line 12 PHP Code:
PHP Code:
__________________
OUTLAW-WEB.NET Last edited by Turbocharged_06; 03-31-2007 at 08:42 PM. |
|
||||
|
I have never run into this error myself, but thanks for posting it.
On the no database selected front, try replacing these lines PHP Code:
PHP Code:
What is your PHP version? What is your MySQL version? As this can have a factor in the processing of scripts. You can completely remove the line saying: PHP Code:
Thomas Gray
__________________
http://www.pointserv.co.uk/gfx/deal_..._pointserv.png PointServ.co.uk - One of the UK's cheapest webhosting companies. Last edited by Base; 03-31-2007 at 09:30 PM. |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|