Hello everyone once again. I am probably going to ask a huge favour of you people at Ozzu (Like usual). I am creating a CMS that I may be selling in the future. I'm having a problem with the database connection and the installation of it.
I have a form that in one section, asks you for the database info (Database Name, Database Username, etc). Since I can't store it in the database (because It's the thing that actually connects to the database), I decided to store it in a flat file (.txt).
I'm having a lot of errors though. This is what I have currently.
Install page 1:
[php]<html>
<head>
<meta http-equiv="Content-Language" content="en-au">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>:: Installation ::</title>
<style>
<!--
input { border-style: solid; border-width: 1 }
-->
</style>
</head>
<body bgcolor="#EAF4FF" style="margin-left:0px; margin-top:0px;">
<div align="left">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-right-width:0; border-bottom-width:0" bordercolor="#111111" width="100%" height="534" id="AutoNumber1">
<tr>
<td width="959" height="83" style="border-left-style:solid; border-left-width:1; border-right-style:solid; border-right-width:1; border-top-style:solid; border-top-width:1" bgcolor="#336699" colspan="2"><?php include("Banner.php"); ?>?></td>
</tr>
<tr>
<td width="959" height="14" style="border-style: solid; border-width: 1; " colspan="2" bgcolor="#FFCC00"> </td>
</tr>
<tr>
<td width="10" height="424" style="border-left-style:none; border-left-width:medium; border-right-style:none; border-right-width:medium" rowspan="4" valign="top"> </td>
<td width="793" height="20" style="border-left-style:none; border-left-width:medium; border-right-style:none; border-right-width:medium; border-bottom-style:none; border-bottom-width:medium" valign="top"></td>
</tr>
<tr>
<td width="793" height="7" style="border-style:none; border-width:medium; " valign="top">
<p align="left">
<font face="Verdana" size="2">Thank you for choosing XCue. In order to use
it however, you must fill in the requested details below. <br>
Make sure that your Database has been created, before you fill in the
form.</font></td>
</tr>
<tr>
<td width="793" height="8" style="border-style:none; border-width:medium; " valign="top"></td>
</tr>
<tr>
<td width="793" height="404" style="border-left-style:none; border-left-width:medium; border-right-style:none; border-right-width:medium; border-top-style:none; border-top-width:medium" valign="top">
<form method="post" action="Install2.php">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="122%" id="AutoNumber2" height="4">
<tr>
<td width="100%" height="25" bgcolor="#003366" align="left" colspan="2">
<p align="center"><b><font face="Verdana" color="#FFFFFF">Details</font></b></td>
</tr>
<tr>
<td width="33%" height="4" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
<p><b><font face="Verdana" size="2">Name:</font></b></td>
<td width="67%" height="4" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
<input type="text" name="Name" size="51"></td>
</tr>
<tr>
<td width="33%" height="1" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
<p><b><font face="Verdana" size="2">Email Address:</font></b></td>
<td width="67%" height="1" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
<input type="text" name="Email" size="51"></td>
</tr>
<tr>
<td width="33%" height="1" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
<i><font face="Verdana" size="1">*Optional*</font></i><font face="Verdana" size="2"><i>
</i><b>Company:</b></font></td>
<td width="67%" height="1" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
<input type="text" name="Company" size="51"></td>
</tr>
<tr>
<td width="100%" height="25" bgcolor="#003366" align="center" style="border-right-style: none; border-right-width: medium" colspan="2">
<b><font face="Verdana" color="#FFFFFF">Database Configuration</font></b></td>
</tr>
<tr>
<td width="32%" height="19" bgcolor="#CCCCCC" align="center" style="border-right-style: none; border-right-width: medium" bordercolor="#808080">
<b><font face="Verdana" size="2">Database Server Hostname:</font></b></td>
<td width="68%" height="19" bgcolor="#CCCCCC" align="center" style="border-right-style: none; border-right-width: medium" bordercolor="#808080">
<p align="left"><input type="text" name="Database_Host" size="51"></td>
</tr>
<tr>
<td width="33%" height="20" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
<b><font face="Verdana" size="2">Your Database Name:</font></b></td>
<td width="67%" height="20" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
<input type="text" name="Database_Name" size="51"></td>
</tr>
<tr>
<td width="33%" height="20" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
<b><font face="Verdana" size="2">Database Username:</font></b></td>
<td width="67%" height="20" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
<input type="text" name="Database_Username" size="51"></td>
</tr>
<tr>
<td width="33%" height="1" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
<b><font face="Verdana" size="2">Database Password:</font></b></td>
<td width="67%" height="1" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
<input type="text" name="Database_Password" size="51"></td>
</tr>
<tr>
<td width="100%" height="25" bgcolor="#003366" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080" colspan="2">
<b><font face="Verdana" color="#FFFFFF">Server Configuration</font></b></td>
</tr>
<tr>
<td width="33%" height="20" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
<b><font face="Verdana" size="2">Domain URL:</font></b></td>
<td width="67%" height="20" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
<input type="text" name="URL" size="51"></td>
</tr>
<tr>
<td width="33%" height="12" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
<b><font face="Verdana" size="2">Script Path:</font></b></td>
<td width="67%" height="12" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
<input type="text" name="Path" size="51"></td>
</tr>
<tr>
<td width="33%" height="8" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
<b><font face="Verdana" size="2">Server Port:</font></b></td>
<td width="67%" height="8" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
<input type="text" name="Server_Port" size="51"></td>
</tr>
<tr>
<td width="100%" height="25" bgcolor="#003366" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080" colspan="2">
<b><font face="Verdana" color="#FFFFFF">Administration Configuration</font></b></td>
</tr>
<tr>
<td width="33%" height="9" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
<b><font face="Verdana" size="2">Admin Username:</font></b></td>
<td width="67%" height="9" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
<input type="text" name="Admin_User" size="51"></td>
</tr>
<tr>
<td width="33%" height="7" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
<b><font face="Verdana" size="2">Admin Password:</font></b></td>
<td width="67%" height="7" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
<input type="text" name="Admin_Pass" size="51"></td>
</tr>
<tr>
<td width="33%" height="11" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
<b><font face="Verdana" size="2">Admin Password Confirm:</font></b></td>
<td width="67%" height="11" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
<input type="text" name="Admin_Pass2" size="51"></td>
</tr>
<tr>
<td width="100%" height="4" bgcolor="#A7A7A7" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080" colspan="2">
<p>
<input type="submit" value="Begin Installation" style="color: #000000; font-family: Verdana; font-size: 10pt; font-weight: bold; border: 3px outset #336699; background-color: #FFFFFF"></td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td width="952" height="20" style="border-style: solid; border-width: 1; " bgcolor="#336699" valign="top" colspan="2"> </td>
</tr>
</table>
</div>
</body>
</html>[/php]
Install Page 2:
[php]<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>:: Installation ::</title>
</head>
<body>
<?php
//Inputs the user's referer into the variable
$ref = $_SERVER['HTTP_REFERER'];
//Writes data to the text file for the database connection
$openfile = fopen("../Database/Database_Connection.txt","a");
fwrite($openfile,$database_host . "\n");
fwrite($openfile,$database_name . "\n");
fwrite($openfile,$database_user . "\n");
fwrite($openfile,$database_pass . "\n");
fclose($openfile);
//Inputs the data from the previous form, into variables
$database_host = $_POST['Database_Host'];
$database_name = $_POST['Database_Name'];
$database_user = $_POST['Database_Username'];
$database_pass = $_POST['Database_Password'];
//If the person did not come from Install.php, it redirects them
if(empty($ref))
{
header("location:Install.php");
}
//The following code will delete the 'Install' directory/folder
function delete_directory($dirname) {
if (is_dir($dirname))
$dir_handle = opendir($dirname);
if (!$dir_handle)
return false;
while($file = readdir($dir_handle)) {
if ($file != "." && $file != "..") {
if (!is_dir($dirname."/".$file))
unlink($dirname."/".$file);
else
delete_directory($dirname.'/'.$file);
}
}
closedir($dir_handle);
rmdir($dirname);
return true;
}
?>
</body>
</html>
[/php]
and the database connection page - config.php:
[php]<?php
@$host = file_get_contents($connect_to_database,1);
@$account = file_get_contents($connect_to_database,2);
@$password = file_get_contents($connect_to_database,3);
@$dbname = file_get_contents($connect_to_database,4);
$connect_to_database = fopen("Database_Connection.txt","a");
$connect = mysql_connect($host,$account,$password);
$db = mysql_select_db($dbname,$connect)
or die("Can't connect to the database");
?>[/php]
How am I to get this to work? Any help on this will be muchly appreciated
