| ![]() ![]() ![]() ![]() |
| |||||||
| Register | Search | Today's Posts | Mark Forums Read |
| Tags: advanced, install, installation, oop, php |
| | LinkBack | Thread Tools |
| ||
| Advanced Installation in OOP (PHP) So we've got the OOP side of the Advanced Installation, but now how do we go about doing the PHP side of it? Well this tutorial is going to help you learn that. The first thing we need to do though is include the file we need. The file that we need is the file with out class in it, which I saved in classes/install.php. We then create the new object and get the x from the url ?x= Code: <?php
require_once('classes/install.php');
$install = new install;
$x = $_GET['x'];
?> Code: <?php
switch($x)**
default:
break;
}
?> Now we fill in the default content, this content will be for setting up our mysql information, there are four fields we need to ask for, mysql host, mysql username, mysql password and the database name. Code: <?php
print 'Welcome to the installation for Silver Blog. This installation file will guide you through to setting up the database and admin.<br /><br />
<form method="post" action="?x=1">
<strong>MySQL Host</strong><br />
<em>This is the host of your mysql, usually localhost.</em><br />';
$install->do_form('','db_host');
print'<strong>MySQL Username</strong><br />
<em>The username for your database.</em><br />';
$install->do_form('','db_user');
print'<strong>MySQL Password</strong><br />
<em>The password for your database.</em><br />';
$install->do_form('password','db_pass');
print'<strong>Database Name</strong><br />
<em>The database to put the tables in</em><br />';
$install->do_form('text','db_name');
$install->do_form('submit','submit');
print'</form>';
?> If you look where our form action is, we direct this form to ?x=1, so we're going to the next step with this. Code: <?php
case'1':
break;
?> Code: <?php
$install->db_host = $install->check_form($_POST['db_host']);
$install->db_user = $install->check_form($_POST['db_user']);
$install->db_pass = $install->check_form($_POST['db_pass']);
$install->db_name = $install->check_form($_POST['db_name']);
?> Code: <?php
if($install->error)**
$install->check_error();
exit();
}
?> Code: <?php
$install->check_connect();
?> Code: <?php
case '2':
break;
?> Code: <?php
print'Creating table blog...<br />';
$sql = 'CREATE TABLE `blog`(
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`title` VARCHAR(30) NOT NULL,
`user` VARCHAR(30) NOT NULL,
`postdate` VARCHAR(70) NOT NULL,
`message` TEXT NOT NULL
) ENGINE = MYISAM ;';
$install->query($sql);
$install->redir('3');
?> Code: <?php
case'3':
break;
?> Code: <?php
print 'Creating table blog...<br />
Table blog created...';
$sql = "INSERT INTO `blog`
(`title`,`user`,`postdate`,`message`) VALUES
('Welcome','Dummy','".date('D M y g:ia')."','This message is to confirm that you have installed the news system.')";
$install->query($sql);
$install->redir('4');
?> Code: <?php
case'4':
print'Creating table blog...<br />
Table blog created...<br />
Creating table blog_comments...<br />';
$sql = 'CREATE TABLE `blog_comments`(
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`blog_id` INT(11) NOT NULL,
`user` VARCHAR(30) NOT NULL,
`postdate` VARCHAR(70) NOT NULL,
`message` TEXT NOT NULL
) ENGINE = MYISAM ;';
$install->query($sql);
$install->redir('5');
break;
case'5':
print 'Creating table blog...<br />
Table blog created...<br />
Creating table blog_comments...<br />
Table blog_comments created...';
$sql = "INSERT INTO `blog_comments` (`blog_id`,`user`,`postdate`,`message`) VALUES ('1','Dummy','".date('D M y g:ia')."','This message is to confirm that you have installed the news system.')";
$install->query($sql);
$install->redir('6');
break;
case'6':
print'Creating table blog...<br />
Table blog created...<br />
Creating table blog_comments...<br />
Table blog_comments created...<br />
Creating table members...<br />';
$sql = "CREATE TABLE `members`(
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`username` INT(11) NOT NULL,
`password` VARCHAR(30) NOT NULL,
`email` VARCHAR(70) NOT NULL,
`joined` VARCHAR(70) NOT NULL,
`level` INT(1) NOT NULL default '1',
`banned` INT(1) NOT NULL default '0'
) ENGINE = MYISAM ;";
$install->query($sql);
$install->redir('7');
break;
case'7':
print 'Creating table blog...<br />
Table blog created...<br />
Creating table blog_comments...<br />
Table blog_comments created...<br />
Creating table members...<br />
Table members created...';
$install->redir('8');
break;
?> Code: <?php
case'8':
print 'Enter in the fields below add your admin account.<br /><br />
<form method="post" action="?x=9">
<strong>Username</strong><br />';
$install->do_form('text','username');
print '<strong>Password</strong><br />';
$install->do_form('password','password');
print '<strong>Email</strong><br />';
$install->do_form('text','email');
$install->do_form('submit','submit');
break;
?> Code: <?php
case'9':
$user = $install->check_form($_POST['username']);
$pass = $install->check_form($_POST['password']);
$email = $install->check_form($_POST['email']);
if($install->error)**
$install->check_error();
exit();
}
?> Code: <?php
md5(md5($pass));
$sql = "INSERT INTO `members`
(`username`,`password`,`email`,`joined`,`level`) VALUES
('$user','$pass','$email','".date('D M y')."','5')";
$install->query($sql);
print 'Successfully added admin.';
$install->redir('10');
break;
?> Code: <?php
case'10':
$install->delete($_SERVER['SCRIPT_FILENAME']);
print 'This installation script has attempted to delete the installation file, you should double check to make sure that it has succeeded.<br /><br />
You can now log in.';
break;
?> Code: <?php
require_once('classes/install.php');
$install = new install;
$x = $_GET['x'];
switch($x)**
default:
print 'Welcome to the installation for Silver Blog. This installation file will guide you through to setting up the database and admin.<br /><br />
<form method="post" action="?x=1">
<strong>MySQL Host</strong><br />
<em>This is the host of your mysql, usually localhost.</em><br />';
$install->do_form('','db_host');
print'<strong>MySQL Username</strong><br />
<em>The username for your database.</em><br />';
$install->do_form('','db_user');
print'<strong>MySQL Password</strong><br />
<em>The password for your database.</em><br />';
$install->do_form('password','db_pass');
print'<strong>Database Name</strong><br />
<em>The database to put the tables in</em><br />';
$install->do_form('text','db_name');
die("This script has died due to you copy and pasting, read through it.");
//DELETE THE LINE ABOVE
$install->do_form('submit','submit');
print'</form>';
break;
case'1':
$install->db_host = $install->check_form($_POST['db_host']);
$install->db_user = $install->check_form($_POST['db_user']);
$install->db_pass = $install->check_form($_POST['db_pass']);
$install->db_name = $install->check_form($_POST['db_name']);
if($install->error)**
$install->check_error();
exit();
}
$install->check_connect();
break;
case'2':
print'Creating table blog...<br />';
$sql = 'CREATE TABLE `blog`(
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`title` VARCHAR(30) NOT NULL,
`user` VARCHAR(30) NOT NULL,
`postdate` VARCHAR(70) NOT NULL,
`message` TEXT NOT NULL
) ENGINE = MYISAM ;';
$install->query($sql);
$install->redir('3');
break;
case'3':
print 'Creating table blog...<br />
Table blog created...';
$sql = "INSERT INTO `blog`
(`title`,`user`,`postdate`,`message`) VALUES
('Welcome','Dummy','".date('D M y g:ia')."','This message is to confirm that you have installed the news system.')";
$install->query($sql);
$install->redir('4');
break;
case'4':
print'Creating table blog...<br />
Table blog created...<br />
Creating table blog_comments...<br />';
$sql = 'CREATE TABLE `blog_comments`(
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`blog_id` INT(11) NOT NULL,
`user` VARCHAR(30) NOT NULL,
`postdate` VARCHAR(70) NOT NULL,
`message` TEXT NOT NULL
) ENGINE = MYISAM ;';
$install->query($sql);
$install->redir('5');
break;
case'5':
print 'Creating table blog...<br />
Table blog created...<br />
Creating table blog_comments...<br />
Table blog_comments created...';
$sql = "INSERT INTO `blog_comments`
(`blog_id`,`user`,`postdate`,`message`) VALUES
('1','Dummy','".date('D M y g:ia')."','This message is to confirm that you have installed the news system.')";
$install->query($sql);
$install->redir('6');
break;
case'6':
print'Creating table blog...<br />
Table blog created...<br />
Creating table blog_comments...<br />
Table blog_comments created...<br />
Creating table members...<br />';
$sql = "CREATE TABLE `members`(
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`username` INT(11) NOT NULL,
`password` VARCHAR(30) NOT NULL,
`email` VARCHAR(70) NOT NULL,
`joined` VARCHAR(70) NOT NULL,
`level` INT(1) NOT NULL default '1',
`banned` INT(1) NOT NULL default '0'
) ENGINE = MYISAM ;";
$install->query($sql);
$install->redir('7');
break;
case'7':
print 'Creating table blog...<br />
Table blog created...<br />
Creating table blog_comments...<br />
Table blog_comments created...<br />
Creating table members...<br />
Table members created...';
$install->redir('8');
break;
case'8':
print 'Enter in the fields below add your admin account.<br /><br />
<form method="post" action="?x=9">
<strong>Username</strong><br />';
$install->do_form('text','username');
print '<strong>Password</strong><br />';
$install->do_form('password','password');
print '<strong>Email</strong><br />';
$install->do_form('text','email');
$install->do_form('submit','submit');
break;
case'9':
$user = $install->check_form($_POST['username']);
$pass = $install->check_form($_POST['password']);
$email = $install->check_form($_POST['email']);
if($install->error)**
$install->check_error();
exit();
}
md5(md5($pass));
$sql = "INSERT INTO `members`
(`username`,`password`,`email`,`joined`,`level`) VALUES
('$user','$pass','$email','".date('D M y')."','5')";
$install->query($sql);
print 'Successfully added admin.';
$install->redir('10');
break;
case'10':
$install->delete($_SERVER['SCRIPT_FILENAME']);
print 'This installation script has attempted to delete the installation file, you should double check to make sure that it has succeeded.<br /><br />
You can now log in.';
break;
}
?>
__________________ |