Jump to content

Recommended Posts

I want to create a new an install script for my CMS, but im not sure how i should go about it.

 

heres my idea.

 

I have a folder within the CMS called install, and in there i have index.php, and a folder called steps. Then in the index.php file i have a an if statement of some sort that checks a variable called $step, to see if it's value is 1 - 3 or how ever many steps i have.

 

Then displays the appropiate page that corresponds with the value of $step.

 

for example

 

$step = 2

 

(displays page 2 from the steps folder.

 

and so on is this a system if not how could i change it.

 

Or even suggest how i could do it a different way.

Link to comment
https://forums.phpfreaks.com/topic/166530-solved-cms-install-script/
Share on other sites

There are a few ways you can do it, you could also instead of using numbers name each step by what they do (e.g. installdb):

$page = $_GET['page'];
$directory = realpath('/relative/path/to/steps/directory');
$file = implode(DIRECTORY_SEPARATOR, array($directory, $page . '.ext'));
if (!$page || !ctype_alpha($page) || !file_exists($file)) {
    //invalid
}

require($file);

 

Or as you are using a wizard, you could use: http://www.phpfreaks.com/forums/index.php/topic,261112.msg1229397.html#msg1229397

ok i got ya i will post what i decide to do i posted on another forum and they said

 

Just create an install.php file with all of the html code in there, with each respective section within if/else statements. For example:

 

if (!isset($_POST['step']) || empty($_POST))
{
    [step one code here]
}
else if (isset($_POST['step']) && $_POST['step'] == '2')
{
    [step two code here]
}

etc.

i decided to go with the code that i posted in my last reply.

 

So i started coding and got the first step of installing my cms complete but i got an error and i dont know what the hell the error shows up.

 

heres the error

 

Parse error:  parse error, unexpected T_CONSTANT_ENCAPSED_STRING in step1.php on line 98

 

my code

<?php
        //If the form hasn't been submitted, show it.
        if (!$_POST['post']) {

?>

<form method="post">
<p>Host <input type="text" class="input" name="host" /></p>
    
    <p>Database Name <input type="text" class="input" name="dbname" /></p>
    
    <p>Database Username<input type="text" class="input" name="dbuser" /></p>
    
    <p>Database Password<input type="text" class="input" name="dbpass" /></p>
    
    <p><input type="submit" class="input" name="submit" value="Continue ->" /></p>

</form>

<?php

        }
        //Or else it has been submitted...
        else {
            //Get information from the forms secure it all.
            
            $host= secure($_POST['host']);
		$dbname = secure($_POST['dname']);
		$dbuser = secure($_POST['dbuser']);
		$dbpass = secure($_POST['dbpass']);


		$connect = mysql_connect($host,$dbuser,dbpass); 

		if ($connect) {
                
			$select = mysql_select_db ($dbname);

				if ($select) {

					$users = "CREATE TABLE `users` (
							  `id` int(5) NOT NULL auto_increment,
							  `username` varchar(30) NOT NULL,
							  `password` varchar(255) NOT NULL,
							  `email` varchar(50) NOT NULL,
							  `location` varchar(50) NOT NULL,
							  `aim` varchar(30) NOT NULL,
							  `msn` varchar(30) default NULL,
							  `gtalk` varchar(30) NOT NULL,
							  `ip` varchar(30) NOT NULL,
							  `signup` varchar(30) NOT NULL,
							  `membergroup` varchar(30) NOT NULL,
							  `bio` varchar(400) NOT NULL,
							  PRIMARY KEY  (`id`)
							);";
					$permissions = "
							CREATE TABLE `permissions` (
							mg_id INT(10) NOT NULL AUTO_INCREMENT,
							mg_name VARCHAR(50) NOT NULL,
							editprofile INT(1) NOT NULL,
							viewprofile INT(1) NOT NULL,
							admin INT(1) NOT NULL,
							moderate INT(1) NOT NULL,
							PRIMARY KEY (`mg_id`)
							);";
					$addperm = "
							INSERT INTO `permissions` 
							(`mg_id`, `mg_name`, `editprofile`, `viewprofile`, `admin`, `moderate`) VALUES 
							(1, 'user', 1, 1, 0, 0),
							(2, 'admin', 1, 1, 1, 1),
							(3, 'guest', 0, 0, 0, 0);
							(4, 'mod', 1, 1, 0, 1);
									";

					$info = "CREATE TABLE `info` (
							`id` INT( 11 ) NOT NULL ,
							`version` VARCHAR( 50 ) NOT NULL ,
							`sitename` VARCHAR( 100 ) NOT NULL ,
							`siteurl` VARCHAR( 100 ) NOT NULL ,
							`sitedesc` TEXT NOT NULL ,
							`aemail` VARCHAR( 300 ) NOT NULL ,
							`emailink` VARCHAR( 300 ) NOT NULL ,
							PRIMARY KEY ( `id` )
							) ENGINE = MYISAM";

					$news "CREATE TABLE `news` (
						   `id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
						   `title` VARCHAR( 50 ) NOT NULL ,
						   `username` VARCHAR( 50 ) NOT NULL ,
						   `date` TIMESTAMP NOT NULL 
						   `body` TEXT NOT NULL ,
						   PRIMARY KEY ( `id` )
						   ) ENGINE = MYISAM";

					$nav = "CREATE TABLE `nav` (
							`id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
							`linkname` VARCHAR( 50 ) NOT NULL ,
							`url` VARCHAR( 100 ) NOT NULL ,
							PRIMARY KEY ( `id` )
							) ENGINE = MYISAM";

					$donwloads = "CREATE TABLE `downloads` (
								 `id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
								 `name` VARCHAR( 100 ) NOT NULL ,
								 `url` VARCHAR( 100 ) NOT NULL ,
								 `date` VARCHAR( 20 ) NOT NULL ,
								 `username` VARCHAR( 50 ) NOT NULL ,
								 PRIMARY KEY ( `id` )
								 ) ENGINE = MYISAM";

					$games = "CREATE TABLE `games` (
							 `id` INT NOT NULL AUTO_INCREMENT ,
							 `name` VARCHAR( 20 ) NOT NULL ,
							 `source` VARCHAR( 100 ) NOT NULL ,
							 `gamedesc` TEXT NOT NULL ,
							 PRIMARY KEY ( `id` )
							 ) ENGINE = MYISAM ";

		}else{
					echo "Error message = ".mysql_error();

		}else{
               echo "Error message = ".mysql_error(); 
		}


            $update = mysql_query("UPDATE info SET sitename = '$sitename', siteurl = '$siteurl', sitedesc = '$sitedesc', aemail = '$aemail' WHERE id = '1'");

            //A query to update everything

}


?>

 

the troubled line(according to the error)(where i placed the bold tags is line 98

 

) $news "CREATE TABLE `news` (
						   `id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
						   `title` VARCHAR( 50 ) NOT NULL ,
						   `username` VARCHAR( 50 ) NOT NULL ,
						   `date` TIMESTAMP NOT NULL 
						   `body` TEXT NOT NULL ,
						   PRIMARY KEY ( `id` )
						   [b]) ENGINE = MYISAM";[/b]

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.