Web Hosting Deals Holiday Logo Design Webcam Chat Website Header Templates Register domain Search Engine Optimisation Web Hosting
Go Back   Talk Mania Forum > Tutorials > PHP / Perl / Java / JavaScript / CGI Tutorials

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.

 Image
Buy Sell Downloads

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-28-2007, 03:14 PM
Base's Avatar
Senior Member
 
Join Date: Mar 2007
Location: North Yorkshire, UK
Posts: 121
Base is on a distinguished road
Send a message via MSN to Base Send a message via Skype™ to Base
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:
<?php
// The MySQL info, edit these
$host "localhost"// the database location. if you dont know it, leave it as it is
$dbuser "DB_USER"// the database username
$dbpass "DB_PASS"// the databases user's pass
$dbname "DB_NAME"// the name of the database

// The actual connection. DO NOT EDIT THESE
mysql_connect("$host","$dbuser","$dbpass"); // Using the variables stated above 
mysql_select_db("$dbname");

?>
Ok so lets go through that line by line:

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.)

Attached Files
File Type: zip PixN.zip (1.3 KB, 36 views)
__________________
http://www.pointserv.co.uk/gfx/deal_..._pointserv.png
PointServ.co.uk - One of the UK's cheapest webhosting companies.
Reply With Quote
  #2 (permalink)  
Old 03-28-2007, 06:02 PM
Junior Member
 
Join Date: Mar 2007
Posts: 25
Willyke is on a distinguished road
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
Reply With Quote
  #3 (permalink)  
Old 03-28-2007, 07:29 PM
Base's Avatar
Senior Member
 
Join Date: Mar 2007
Location: North Yorkshire, UK
Posts: 121
Base is on a distinguished road
Send a message via MSN to Base Send a message via Skype™ to Base
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.
Reply With Quote
  #4 (permalink)  
Old 03-31-2007, 07:47 PM
Turbocharged_06's Avatar
VIP Member
 
Join Date: Mar 2007
Posts: 151
Turbocharged_06 is on a distinguished road
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
and here are my settings p.s. password is fake

PHP Code:
<?php

$host 
"mysql3.freehostia.com";
$dbuser "turcha_mysql"
$dbpass "pass1";
$dbname "users";

mysql_connect("$host","$dbuser","$dbpass"); 
mysql_select_db("$dbname");

$seperate-connect 'mysql_connect("$host","$dbuser","$dbpass");';
?>
but it works like this
PHP Code:
<?php
// The MySQL info, edit these
$host "mysql3.freehostia.com"// the database location. if you dont know it, leave it as it is
$dbuser "turcha_mysql"// the database username
$dbpass "allah1"// the databases user's pass
$dbname "wb_users"// the name of the database

// The actual connection. DO NOT EDIT THESE
mysql_connect("$host","$dbuser","$dbpass"); // Using the variables stated above 
mysql_select_db("$dbname");


?>
but then it says no database selected
__________________
OUTLAW-WEB.NET

Last edited by Turbocharged_06; 03-31-2007 at 08:42 PM.
Reply With Quote
  #5 (permalink)  
Old 03-31-2007, 09:27 PM
Base's Avatar
Senior Member
 
Join Date: Mar 2007
Location: North Yorkshire, UK
Posts: 121
Base is on a distinguished road
Send a message via MSN to Base Send a message via Skype™ to Base
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:
mysql_connect("$host","$dbuser","$dbpass"); // Using the variables stated above 
mysql_select_db("$dbname"); 
With this:

PHP Code:
mysql_connect($host$dbuser$dbpass); // Using the variables stated above 
mysql_select_db($dbname); 
As i say i have tested it on my local machine and on my web servers, and it works perfectly.

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:
$seperate-connect 'mysql_connect("$host","$dbuser","$dbpass");'
Thanks

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.
Reply With Quote
  #6 (permalink)  
Old 04-01-2007, 04:45 AM
Junior Member
 
Join Date: Apr 2007
Posts: 3
Julio Cesar is on a distinguished road
excellent!!!!!!!!

Muito bom esse seu artigo ( very good !!!!!)
Reply With Quote
  #7 (permalink)  
Old 04-04-2007, 07:06 PM
Junior Member
 
Join Date: Mar 2007
Posts: 20
kraze101 is on a distinguished road
maybe the php.ini file is not corrected for mysql in the post where they having problems up there. i dunno maybe a suggestion.??or maybe missing some syntax those are easy to miss.
Reply With Quote
  #8 (permalink)  
Old 04-14-2007, 04:32 PM
Junior Member
 
Join Date: Apr 2007
Posts: 3
Darkless is on a distinguished road
Cool, Helps a lot
Reply With Quote
  #9 (permalink)  
Old 04-24-2007, 05:14 AM
Junior Member
 
Join Date: Apr 2007
Posts: 4
chixor1 is on a distinguished road
Looking forward to wlaking through this tutorial, thanks for taking the time to make it.
Reply With Quote
  #10 (permalink)  
Old 04-25-2007, 08:18 PM
Junior Member
 
Join Date: Apr 2007
Posts: 3
surgeboard is on a distinguished road
Best beginner tutorial I have ever read. Thank you.

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +2. The time now is 01:24 AM.


Fake ID

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC8
Forums Copyright © Talk-Mania.com