MicrotechXP
New Member
- Messages
- 7,644
- Reaction score
- 0
- Points
- 0
Anyone know where I can get an tut for making an install script? :hsdance:
MicrotechXP said:I was looking for a php one.
I want one to help my freind. He is making a CMS and he neads a install script for it.:runaway:The_End said:ha ha, but it needs to do something
theres millions of install scripts
forums installer, account, ad, users, etc
Yes thats what he neads...they MySAL things...he wants a script that can install his script.Bryon said:You say you need an install script, but what do you mean exactly?
If by saying "install script" you mean a script where you:
Have someone fill out some information (Such as MySQL connection data) and have it create a site's database tables then populate them with configuration data, or even creating a "configuration" file to be included after the installation has finished.(I think I might have worded that a little weird, sorry.)
You could create something like that easily, using a little PHP with HTML(Forms), even a few MySQL queries. Your probably not going to find a tutorial really on somethign like this, since it's not exactly.. Hmm, the same thing for everyone. I would think this type of thing varies from "job to job".
Well is that what you are looking to create, or am I off by a lot?
<html>
<head>
<title>Install</title>
<link rel="stylesheet" title="default" type="text/css" media="screen" href="style.css">
</head>
<body>
<?php
$showForm = 'Yes';
function installScript() {
global $showForm;
$host = $_POST['mysqlHost'];
$username = $_POST['mysqlUsername'];
$password = $_POST['mysqlPassword'];
$database = $_POST['mysqlDatabase'];
$adminusername = $_POST['adminUsername'];
$adminpassword = $_POST['adminPassword'];
$string = '';
if ((!$host) OR (!$username) OR (!$password) OR (!$database) OR (!$adminusername) OR (!$adminpassword)) {
return '<span class="error"><b>Error!</b> You must fill out all fields.</span><br />';
}
$connect = @mysql_connect($host, $username, $password);
if($connect != false) {
$string .= ' <b>-Step 1</b>: Connected to mysql server.<br />';
} else {
return '<span class="error"><b>Error!</b> There was a problem connecting to the MySQL Server.<br /><b>MySQL Said</b>: '. mysql_error() .'</span>';
}
$sdatabase = @mysql_select_db($database);
if($sdatabase != false) {
$string .= ' <b>-Step 2</b>: Selected the database.<br />';
} else {
return $string .'<span class="error"><b>Error!</b> The database could not be selected. Please check the name and<br />make sure the mysql account has access to the database.</span><br />';
}
@mysql_query("DROP TABLE IF EXISTS `nedren_newsposts`") or die(mysql_error());
@mysql_query("DROP TABLE IF EXISTS `nedren_newsadmins`") or die(mysql_error());
$table1_sql = "CREATE TABLE `nedren_newsposts` (`id` INT( 16 ) NOT NULL AUTO_INCREMENT ,`title` VARCHAR( 100 ) NOT NULL ,`body` TEXT NOT NULL ,`date` VARCHAR( 32 ) NOT NULL ,`time` VARCHAR( 32 ) NOT NULL ,`timestamp` VARCHAR( 32 ) NOT NULL ,`username` VARCHAR( 32 ) NOT NULL ,PRIMARY KEY ( `id` )) TYPE = MYISAM COMMENT = 'Table to hold news posts for nedrens news poster'";
$table2_sql = "CREATE TABLE `nedren_newsadmins` ( `id` int(16) NOT NULL auto_increment, `username` varchar(32) NOT NULL default '', `password` varchar(32) NOT NULL default '', `last_login` varchar(32) NOT NULL default '', `total_posts` varchar(32) NOT NULL default '', `type` varchar(32) NOT NULL default '', `keep` varchar(32) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM COMMENT='Table to hold admin news posting accounts for nedren''s news ' AUTO_INCREMENT=3 ;";
$table1_results = @mysql_query($table1_sql);
if($table1_results != false) {
$string .= ' <b>-Step 3</b>: Table `nedren_newsposts` created.<br />';
} else {
return $string .'<span class="error"><b>Error!</b> Table `nedren_newsposts` could not be created.</span><br /><b>MySQL Said</b>: '. mysql_error() .'</span>';
}
$table2_results = @mysql_query($table2_sql);
if($table2_results != false) {
$string .= ' <b>-Step 4</b>: Table `nedren_admins` created.<br />';
} else {
return $string .'<span class="error"><b>Error!</b> Table `nedren_newsadmins` could not be created.</span><br /><b>MySQL Said</b>: '. mysql_error() .'</span>';
}
$date = date("m/d/y");
$time = date("g:i a");
$timestamp = time();
@mysql_query("INSERT INTO `nedren_newsposts` (`title`,`body`,`date`,`time`,`timestamp`,`username`) VALUES ('Welcome!','Welcome to NedreN\'s News System. Thank you for installing this and using it. If you have any problems, questions, or suggestions, you can contact me at <a href=\"http://nedren.com/contact.php\">NedreN.com</a>.','$date','$time','$timestamp','System')") or die(mysql_error());
$admin_results = @mysql_query("INSERT INTO `nedren_newsadmins` (`username`,`password`,`total_posts`,`type`,`keep`) VALUES ('$adminusername','$adminpassword','0','Admin','Yes')");
if($admin_results != false) {
$string .= ' <b>-Step 5</b>: Administrator account added.<br />';
} else {
return $string .'<span class="error"><b>Error!</b> Administrator account could not be added..</span><br /><b>MySQL Said</b>: '. mysql_error() .'</span>';
}
$string .= '<br /><span class="worked"><b>Success!</b> Everything was set up correctly. You can now use your news posting system!</span><br />';
$showForm = 'No';
return $string;
}
if (!$_POST['mysqlHost']) {
$_POST['mysqlHost'] = 'localhost';
}
?>
<form action="install.php" method="post">
<table id="installTable">
<tr>
<td colspan="2" class="alignCenter"><h3>Install NedreN's News System</h3></td>
</tr>
<tr>
<td colspan="2" class="alignCenter">Fill out your required information and submit to install NedreN's News System</td>
</tr>
<?php
if ($_POST['submit']) {
echo '<tr><td class="results">'. installScript() .'</td></tr>';
}
?>
<tr>
<td>
<?php
if ($showForm != 'No') {
?>
<center>
<table id="installSubTable">
<tr>
<td><b>MySQL Host</b>:</td>
<td><input type="text" name="mysqlHost" value="<?php echo $_POST['mysqlHost']; ?>" size="25" /></td>
</tr>
<tr>
<td><b>MySQL Username</b>:</td>
<td><input type="text" name="mysqlUsername" value="<?php echo $_POST['mysqlUsername']; ?>" size="25" /></td>
</tr>
<tr>
<td><b>MySQL Password</b>:</td>
<td><input type="text" name="mysqlPassword" value="<?php echo $_POST['mysqlPassword']; ?>" size="25" /></td>
</tr>
<tr>
<td><b>MySQL Database</b>:</td>
<td><input type="text" name="mysqlDatabase" value="<?php echo $_POST['mysqlDatabase']; ?>" size="25" /></td>
</tr>
<tr>
<td><b>Administrator Username</b>:</td>
<td><input type="text" name="adminUsername" value="<?php echo $_POST['adminUsername']; ?>" size="25" /></td>
</tr>
<tr>
<td><b>Administrator Password</b>:</td>
<td><input type="text" name="adminPassword" value="<?php echo $_POST['adminPassword']; ?>" size="25" /></td>
</tr>
<tr>
<td colspan="2" class="alignCenter"><input type="submit" name="submit" value="Install" /></td>
</tr>
</table>
</center>
<?php
}
?>
</td>
</tr>
</table>
</form>
</body>