
PLEASE CHECK OUT THE SECOND VIDEO OF THIS A quick and easy user registration using php, sql and phpmyadmin. For full size and source codes: www.neoblob.com SQL: CREATE TABLE `user` ( `id` int(10) unsigned NOT NULL auto_increment, `username` varchar(20) NOT NULL default ”, `password` varchar(50) NOT NULL default ”, `email` varchar(40) NOT NULL default ”, `ip` varchar(20) NOT NULL default ”, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;…
In this article I’ll try to describe how to develop a very simple Content Management System (CMS). I’ve chosen PHP as the server-side scripting language and MySQL as the database management system purely because I think they are fairly easy to use and they do the job very well.
I won’t spend any time describing CMSs, what they are, or why you should or should not use them as there are plenty of excellent articles around that describe them perfectly well. I’ll just explain one way of developing a CMS.
This CMS consists of a single web page (index.php) that can have its contents updated by use of a form (editPage.php). The contents entered via the form are stored in a database, and are accessed and displayed by the web page. Although this CMS is too simple to be of any real use, it could be used as the starting point for a real life CMS solution.
There are four files in this project:
cms.sql
editPage.php
updatePage.php
index.php
cms.sql
This file creates a database called cms, and creates a table in that database called page. It also loads some intial data into the table. You only need to use this file once.
editPage.php
This web page contains a simple form that can be used to enter (and edit) the contents displayed by index.php.
updatePage.php
This is the form handler – the script that processes the data (entered in editPage.php) and inserts it into the database table (page).
index.php
This is the web page that displays the data held in the database table.
cms.sql
1. CREATE DATABASE cms;
2. USE cms;
3. CREATE table page (
4. pageID integer auto_increment,
5. contents text,
6. primary key (pageID)
7. );
8. insert into page (pageID, contents) values (’1′, ‘dummy text’);
Line 1 creates a database called cms in the MySQL database management system.
Line 2 tells MySQL to use the database for the subsequent commands.
Line 3 creates a table in the database.
Line 4 creates a column called pageID, which will contain integers, and which will be automatically incremented as new records are added to the table. As we only have one web page (index.php) in our imaginary website, we will only have one record and therefore one integer: 1. If we added additional pages to the table, they would be automatically numbered (2, 3, 4, etc).
Line 5 creates a second column called contents, which will contain text. This is where the editable contents displayed by index.php will be stored.
Line 6 sets pageID as the primary key, which you can think of as a reference for the table. As we only have one table, which will contain only one record, we won’t make any use of the key. I’ve included it though because it’s good practice to do so.
Line 7 simply closes the bit of code that was started in line 3.
Line 8 inserts some intial data into the table: 1 as the first (and only) pageID, and ‘dummy text’ as the contents of the first record.
editPage.php
(Note that for display considerations, I’ve used square brackets ‘[' instead of angle brackets for tag names.)
1. [html]
2. [head]
3. [title]Really Simple CMS[/title]
4. [/head]
5. [body]
6. [h1]Really Simple CMS[/h1]
7. [?php
8. mysql_connect("localhost", "root", "password");
9. $result = @mysql_query("SELECT contents from cms.page");
10. while ($row = mysql_fetch_assoc($result)){
11. $contents = $row['contents']; // Do not change these to angle brackets
12. }
13. ?]
14. [form name="form1" method="post" action="updatePage.php"]
15. Enter page content:[br][textarea rows="10" cols="60" name="contents"][?php echo "$contents" ?][/textarea]
16. [input type="submit" name="Submit" value="Update Page"]
17. [/form]
18. [/body]
19. [/html]
Most of this file is fairly simple HTML that doesn’t need explaining. However, the following bits of code are probably worth discussing.
Lines 7 through to 13 contain PHP code to connect to the database and extract the contents of the web page.
Line 15 contains a tiny bit of PHP code to display the contents in the form’s textarea. This line shows how easy it is to integrate bits of PHP code into lines of HTML code.
Remember though that in order to use PHP code in an HTML page, the file has to have an extension of .php. If it does not, the PHP code will not be processed by the web server.
updatePage.php
1. [?php
2. $contents=$_REQUEST['contents']; // Do not change to angle brackets
3. mysql_connect(“localhost”, “root”, “password”);
4. $result = @mysql_query(“UPDATE cms.page SET contents=’$contents’”);
5. mysql_close();
6. ?]
This is the form handler, that’s to say, the script that processes the data entered into the form (in editPage.php).
Line 1 signifies the start of a PHP script.
Line 2 requests the contents that were posted from the form. We could have written
$contents=$_POST['contents']; instead if we had wanted to.
Line 3 connects to the MySQL database server, setting up the host name, which I’ve assumed to be localhost, the database user, which I’ve assumed to be root, and the password needed to connect to the database. Naturally, I have no idea what this would be for your system so I’ve just written the word password.
Line 4 updates the page table in the cms database with the new contents.
Line 5 closes the database connection.
Line 6 closes the PHP script.
index.php
1. [html]
2. [head]
3. [title]Home Page[/title]
4. [body]
5. [h1]Home Page[/h1]
6. [?php
7. mysql_connect("localhost", "root", "password");
8. $result = mysql_query("select contents from cms.page");
9. while ($row = mysql_fetch_assoc($result)){
10. $contents = $row['contents']; // Do not change to angle brackets
11. }
12. echo $contents;
13. ?]
14. [/body]
15. [/html]
This is the web page that displays the contents from the database.
Most of the lines in this web page are pretty straight forward and don’t need explaining. Lines 6 to 13 contain the PHP script that extracts the contents from the database and displays (echos) it in the browser.
Installing/Running the CMS
To use the CMS you need to copy the files onto your web server into the area allocated for web pages. Your web server needs to support PHP and MySQL; if it doesn’t, the CMS won’t work.
You also need to use the correct database connection names and passwords (those used in the mysql_connect lines in the PHP scripts).
Exactly how you run the cms.sql file to set up the database and database table will vary from web server to web server so it’s difficult to give precise instructions here. If you have a phpMyAdmin icon or something similar in your web servers control/administration panel you should be able to use that.
Once you’ve set up the database and table, you can simply browse to the editPage.php web page and update the database contents. You can then browse to the index.php page to view the updates.
How can i study or try PHP programming at home if I only have a laptop with WIndowsXP SP3 OS?
I want to learn PHP programming but I do not have that big server computers or a network of computers. Is it possible to do PHP programming using only a laptop connected only to internet, through a 3g modem; and running on Windows XP SP3 OS? What are the application and/or software that I need to install to make it work?
php
John Dixon is a web developer working through his own company John Dixon Technology. As well as providing web development services, John’s company also provides free open source accounting software written in PHP and MySQL.









Id personaly recomend php Curl, its a great function of php. You can set it to do lots of stuff, such as fake the refferer!
I use CURL a lot, and use it for google to find websites PR. Here is a snipit of what I use.
<?php
$url = "http://google.com";
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,$url);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$html = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($html)){
print "Sorry, $url could not be found.<p>";
}else{
print $html;
}
?>
yes, you can use MS front page 2003 for woking with PHP but i suggest dreamware is better for php. either both are same.
good luck
create the directories and include the names when using the require() function.
example :
your index.php is in the root directory
/index.php
and you have a directory with your other php files in
/lib/other.php
so in index.php you will have
require("lib/other.php");
on 15.28 – how this “GO BACK” link work ?
Audio quality is horrible.
There is no subtitute of HARD WORK.
As you said have basic development skill in PHP (Personal Home Page) Skill. you mau buyt Unleashed PHP (Sams publication) practice it for month or so and do a project. After that you may buy Mastering PHP (Sams Publication) and gain mastery in PHP.
for .NET learning, its not advisable to learn 2 language of diff type at one go. fist finish PHP then try for .NET.
for .NET fist use MSDN…
buy Learns 21 days in .NET
Unleased .NET (ASP, C# and VB.NET)
Then go for Master series for each of this language.
you MUST DO Certification in these language.
Good Luck.
Thank you coopaloop86!!
If he fails at English who really cares? we are not his English teacher anyway you IDIOT
some addvice you have the register page connecting to the db twice you only have to connect 1ce on each page
Ok, this makes marginally more sense. So, you want your PHP to return a variable to the JavaScript? Try a hidden field:
<input id="myHiddenField" value="myValue" type="hidden" hidden/>
and the js:
var value = document.getElementById('myHiddenField').value;
if that is not the case, if you are trying to get a JS variable into PHP, that cannot be done.
PHP is a server side language, which means the code is DONE by the time the web page is displayed. JavaScript is a client side language, which means the code is executed ONCE THE PAGE IS LOADED.
Communication between client-side and server-side languages is limited, and one way (server-side->client-side via hidden field [crude]). I suggest you rethink your method…
oh and good on the commenting that is great for beginners
I would like to point out something that someone has already pointed out: you only have to connect once per script.
Also, I would recommend you didn’t use bad coding practices like the above…
If you only have one ":" symbol in the string, you can use this:
$string = explode(":", $string);
This puts the two halves into an array. So:
$table = $string[0];
$column = $string[1];
willzurmacht –
-> is used to access an entity of an object. In this case the object is $poll and by doing $poll->vote, a function called vote within the poll class will be invoked.
Bloddy Hell. YOUR VOICE IS A BITCH LIKE MY EX!!! IT IS AN ANNOYING SQUEAKING VOICE THAT NEVER SHUTS THE HELL UP!
omg soo many typos in mine.. sooo many erros!!! ahhh CRAZY finnaly fixed thme..
Thanks so much. You finally solved my problem!
And “i nearly dies” with how much you fail at English.
There could easily be better ways to do this, but without actually seeing how your data is organized I only have one workable suggestion.
In post.php, add each post to array and then echo the array contents to output the posts. Then include post.php in homepage.php.
post.php
————-
$post = array();
$post[0] = "<h1>Post #1</h1>This is post #1";
$post[1] = "<h1>Post #2</h1>This is post #2";
$post[2] = "<h1>Post #3</h1>This is post #3";
foreach ($post as $x) {
echo $x;
}
echo "<h1>More posts</h1>More posts here!";
myhome.php
——————-
require_once('post.php'); // Gives you access to all the stuff in post.php
echo "Let's see the first three posts:<br />";
foreach ($post as $x) {
echo $x;
}
echo "Stuff on homepage other than top posts.";
just be glad he showed oyu how besides a minor defect.. mys-q-l is how its pronounced but it looks like mysqaaal
// get array of all files and directories in the current directory (it is sorted alphabetically by default)
$dir_entries = scandir(dirname(__FILE__)); // for PHP 5.3+, use __DIR__ instead of dirname(__FILE__)
// split the array of files and directories into two arrays, one containing files and the other directories
$dir_files = array();
$dir_directories = array();
foreach($dir_entries as $dir_entry) {
if(is_dir($dir_entry)) {
array_push($dir_directories, $dir_entry);
} else {
array_push($dir_files, $dir_entry);
}
}
// print directories
foreach($dir_directories as $dir_directory) {
// don't print current and parent directories
if($dir_directory == '.' or $dir_directory == '..') {
continue;
}
echo "<a href="" . htmlspecialchars($dir_directory) . "">" . htmlspecialchars($dir_directory) . "</a><br/>n";
}
// print files
foreach($dir_files as $dir_file) {
echo "<a href="" . htmlspecialchars($dir_file) . "">" . htmlspecialchars($dir_file) . "</a><br/>n";
}
“or or” “equals equals” lol..
you dont have to say them twice.. and you dont need to set variables unless you are goning to run a “clean and make safe” on variables… you can directly use them on query… but this wont be secure.. so keep setting variables but make them safe….
I mean.. this tutorial is OK for some beginners but why not jus put the host,dbuser,dbpass,and db variables in a config file and at the top jus put include “config.php”; its a much easier way than having to put all that info on a page
here all you have to do is
require_once('whateveryounamemyfile');
$MyMail=new MyMail($To="Email address", $Subject="Subject", $Msg=Message or body, $From="From email address", $ReplyTo="reply to email address.or use from email address");
<?
/***********************
CLASS :: MYMail
************************/
class MyMail{
var $To;
var $Subject;
var $Msg;
var $Headers;
var $From;
var $ReplyTo;
/*
$headers = 'From: webmaster@example.com' . "rn" .
'Reply-To: webmaster@example.com' . "rn" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
***&&&&&*******
For HTML Mail
'MIME-Version: 1.0' . "rn";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
*/
function MyMail($To, $Subject, $Msg, $From, $ReplyTo){
$this->To=(empty($To)) ? "0" : $To;
$this->Subject=(empty($Subject)) ? "0" : $Subject;
$this->Msg=(empty($Msg)) ? "0" : $Msg;
$this->From=(empty($From)) ? "0" : $From;
$this->ReplyTo=(empty($ReplyTo)) ? "0" : $ReplyTo;
$this->Headers="MIME-Version: 1.0" . "rn" . "Content-type: text/html; charset=iso-8859-1" . "rn" . "From:" . $this->From . "rn" . "Reply-To:" . $this->ReplyTo . "rn" . "X-Mailer: PHP/" . phpversion();
$SetMail=array(
'To'=> $this->To,
'Subject'=> $this->Subject,
'Msg'=> $this->Msg,
'Headers'=> $this->Headers,
'From'=> $this->From,
'ReplyTo'=> $this->ReplyTo
);
if(in_array("0",$SetMail)){
echo "<div align="left"><font color="#640000">Something wrong with the mail! Please make sure all fields are filled in!</font></div>";
return;
}
else{
if(!mail($SetMail['To'], $SetMail['Subject'], $SetMail['Msg'], $SetMail['Headers'])){
$this->Errors="SYS";
echo "<script type="text/javascript">window.location="error.php?app=Error&action=Echo&ErrorType=$this->Errors&Remarks=There is a problem with the Mail!"</script>";
}
}
}
}
?>
$MyMail=new MyMail($To="Email address", $Subject="Subject", $Msg=Message or body, $From="From email address", $ReplyTo="reply to email address.or use from email address");
it is used when you have a class reference.
in this example you are using a “function” from you object poll ($poll)
Regards
You could install XAMPP. That will give you Apache web server, PHP and MySQL. It's fairly easy to install and setup. See fist link below.
But DO make sure you secure it once installed, otherwise your machine could be vulnerable. Also not hard to do, read the instructions in the second link.
Warning: show_source() has been disabled for security reasons in /home2/neoblob/public_html/phpsquad/tuts/php/1/index.php on line 87
thank you Mr.MarcosRosa
W3Schools generally has good tutorials:
http://www.w3schools.com/php/php_syntax.asp
For a more thorough approach, see the php.net language reference:
http://www.php.net/manual/en/langref.php
Once you have learned the basics, the php.net function reference is invaluable:
http://www.php.net/manual/en/funcref.php
any time buddy!
“hang on, I get IMed alot….”
use this function
array_slice(array, offset, length, preservekeys)
in your case the function call will be like this
$result_array = array_slice($your_array, 0, 5 );
I would say its a fail at typing, not English
hello I’ve been watching your videos in php since last year.. I just wanna know what is the use of this symbol -> cause I saw my classmate use this for some sort..
i.e $poll->vote($_SESSION['userid'],$_GET['id'],$_POST['option']);
}
“mysquaaal” omg i nearly dies how annoying voice