[SOLVED] CMS Installation - Flat File & Database Connect

  • Funny_Fuzz
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jan 18, 2005
  • Posts: 1519
  • Loc: Australia
  • Status: Offline

Post July 6th, 2005, 12:17 am

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 Code: [ Download ] [ Select ]
<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">&nbsp;</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">&nbsp;</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>
 
      &nbsp;
 
      </td>
 
    </tr>
 
    <tr>
 
      <td width="952" height="20" style="border-style: solid; border-width: 1; " bgcolor="#336699" valign="top" colspan="2">&nbsp;</td>
 
    </tr>
 
  </table>
 
</div>
 
 
 
</body>
 
</html>
  1. <html>
  2.  
  3.  
  4.  
  5. <head>
  6.  
  7. <meta http-equiv="Content-Language" content="en-au">
  8.  
  9.  
  10.  
  11. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  12.  
  13. <title>:: Installation ::</title>
  14.  
  15. <style>
  16.  
  17. <!--
  18.  
  19. input        { border-style: solid; border-width: 1 }
  20.  
  21. -->
  22.  
  23. </style>
  24.  
  25. </head>
  26.  
  27. <body bgcolor="#EAF4FF" style="margin-left:0px; margin-top:0px;">
  28.  
  29.  
  30.  
  31. <div align="left">
  32.  
  33.   <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">
  34.  
  35.     <tr>
  36.  
  37.       <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>
  38.  
  39.     </tr>
  40.  
  41.     <tr>
  42.  
  43.       <td width="959" height="14" style="border-style: solid; border-width: 1; " colspan="2" bgcolor="#FFCC00">&nbsp;</td>
  44.  
  45.     </tr>
  46.  
  47.     <tr>
  48.  
  49.       <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">&nbsp;</td>
  50.  
  51.       <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>
  52.  
  53.     </tr>
  54.  
  55.     <tr>
  56.  
  57.       <td width="793" height="7" style="border-style:none; border-width:medium; " valign="top">
  58.  
  59.       <p align="left">
  60.  
  61.       <font face="Verdana" size="2">Thank you for choosing XCue. In order to use
  62.  
  63.       it however, you must fill in the requested details below. <br>
  64.  
  65.       Make sure that your Database has been created, before you fill in the
  66.  
  67.       form.</font></td>
  68.  
  69.     </tr>
  70.  
  71.     <tr>
  72.  
  73.       <td width="793" height="8" style="border-style:none; border-width:medium; " valign="top"></td>
  74.  
  75.     </tr>
  76.  
  77.     <tr>
  78.  
  79.       <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">
  80.  
  81.       <form method="post" action="Install2.php">
  82.  
  83.       <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="122%" id="AutoNumber2" height="4">
  84.  
  85.         <tr>
  86.  
  87.           <td width="100%" height="25" bgcolor="#003366" align="left" colspan="2">
  88.  
  89.          
  90.  
  91.           <p align="center"><b><font face="Verdana" color="#FFFFFF">Details</font></b></td>
  92.  
  93.         </tr>
  94.  
  95.         <tr>
  96.  
  97.           <td width="33%" height="4" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
  98.  
  99.           <p><b><font face="Verdana" size="2">Name:</font></b></td>
  100.  
  101.           <td width="67%" height="4" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
  102.  
  103.           <input type="text" name="Name" size="51"></td>
  104.  
  105.         </tr>
  106.  
  107.         <tr>
  108.  
  109.           <td width="33%" height="1" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
  110.  
  111.           <p><b><font face="Verdana" size="2">Email Address:</font></b></td>
  112.  
  113.           <td width="67%" height="1" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
  114.  
  115.           <input type="text" name="Email" size="51"></td>
  116.  
  117.         </tr>
  118.  
  119.         <tr>
  120.  
  121.           <td width="33%" height="1" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
  122.  
  123.           <i><font face="Verdana" size="1">*Optional*</font></i><font face="Verdana" size="2"><i>
  124.  
  125.           </i><b>Company:</b></font></td>
  126.  
  127.           <td width="67%" height="1" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
  128.  
  129.           <input type="text" name="Company" size="51"></td>
  130.  
  131.         </tr>
  132.  
  133.         <tr>
  134.  
  135.           <td width="100%" height="25" bgcolor="#003366" align="center" style="border-right-style: none; border-right-width: medium" colspan="2">
  136.  
  137.           <b><font face="Verdana" color="#FFFFFF">Database Configuration</font></b></td>
  138.  
  139.         </tr>
  140.  
  141.         <tr>
  142.  
  143.           <td width="32%" height="19" bgcolor="#CCCCCC" align="center" style="border-right-style: none; border-right-width: medium" bordercolor="#808080">
  144.  
  145.           <b><font face="Verdana" size="2">Database Server Hostname:</font></b></td>
  146.  
  147.           <td width="68%" height="19" bgcolor="#CCCCCC" align="center" style="border-right-style: none; border-right-width: medium" bordercolor="#808080">
  148.  
  149.           <p align="left"><input type="text" name="Database_Host" size="51"></td>
  150.  
  151.           </tr>
  152.  
  153.         <tr>
  154.  
  155.           <td width="33%" height="20" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
  156.  
  157.           <b><font face="Verdana" size="2">Your Database Name:</font></b></td>
  158.  
  159.           <td width="67%" height="20" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
  160.  
  161.           <input type="text" name="Database_Name" size="51"></td>
  162.  
  163.         </tr>
  164.  
  165.         <tr>
  166.  
  167.           <td width="33%" height="20" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
  168.  
  169.           <b><font face="Verdana" size="2">Database Username:</font></b></td>
  170.  
  171.           <td width="67%" height="20" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
  172.  
  173.           <input type="text" name="Database_Username" size="51"></td>
  174.  
  175.         </tr>
  176.  
  177.         <tr>
  178.  
  179.           <td width="33%" height="1" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
  180.  
  181.           <b><font face="Verdana" size="2">Database Password:</font></b></td>
  182.  
  183.           <td width="67%" height="1" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
  184.  
  185.           <input type="text" name="Database_Password" size="51"></td>
  186.  
  187.         </tr>
  188.  
  189.         <tr>
  190.  
  191.           <td width="100%" height="25" bgcolor="#003366" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080" colspan="2">
  192.  
  193.           <b><font face="Verdana" color="#FFFFFF">Server Configuration</font></b></td>
  194.  
  195.           </tr>
  196.  
  197.         <tr>
  198.  
  199.           <td width="33%" height="20" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
  200.  
  201.           <b><font face="Verdana" size="2">Domain URL:</font></b></td>
  202.  
  203.           <td width="67%" height="20" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
  204.  
  205.           <input type="text" name="URL" size="51"></td>
  206.  
  207.         </tr>
  208.  
  209.         <tr>
  210.  
  211.           <td width="33%" height="12" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
  212.  
  213.           <b><font face="Verdana" size="2">Script Path:</font></b></td>
  214.  
  215.           <td width="67%" height="12" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
  216.  
  217.           <input type="text" name="Path" size="51"></td>
  218.  
  219.         </tr>
  220.  
  221.         <tr>
  222.  
  223.           <td width="33%" height="8" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
  224.  
  225.           <b><font face="Verdana" size="2">Server Port:</font></b></td>
  226.  
  227.           <td width="67%" height="8" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
  228.  
  229.           <input type="text" name="Server_Port" size="51"></td>
  230.  
  231.         </tr>
  232.  
  233.         <tr>
  234.  
  235.           <td width="100%" height="25" bgcolor="#003366" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080" colspan="2">
  236.  
  237.           <b><font face="Verdana" color="#FFFFFF">Administration Configuration</font></b></td>
  238.  
  239.         </tr>
  240.  
  241.         <tr>
  242.  
  243.           <td width="33%" height="9" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
  244.  
  245.           <b><font face="Verdana" size="2">Admin Username:</font></b></td>
  246.  
  247.           <td width="67%" height="9" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
  248.  
  249.           <input type="text" name="Admin_User" size="51"></td>
  250.  
  251.         </tr>
  252.  
  253.         <tr>
  254.  
  255.           <td width="33%" height="7" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
  256.  
  257.           <b><font face="Verdana" size="2">Admin Password:</font></b></td>
  258.  
  259.           <td width="67%" height="7" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
  260.  
  261.           <input type="text" name="Admin_Pass" size="51"></td>
  262.  
  263.         </tr>
  264.  
  265.         <tr>
  266.  
  267.           <td width="33%" height="11" valign="middle" bgcolor="#CCCCCC" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080">
  268.  
  269.           <b><font face="Verdana" size="2">Admin Password Confirm:</font></b></td>
  270.  
  271.           <td width="67%" height="11" valign="top" bgcolor="#CCCCCC" bordercolor="#808080">
  272.  
  273.           <input type="text" name="Admin_Pass2" size="51"></td>
  274.  
  275.         </tr>
  276.  
  277.         <tr>
  278.  
  279.           <td width="100%" height="4" bgcolor="#A7A7A7" align="center" style="border-right-style: solid; border-right-width: 1" bordercolor="#808080" colspan="2">
  280.  
  281.           <p>
  282.  
  283.           <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>
  284.  
  285.          
  286.  
  287.           </tr>
  288.  
  289.       </table>
  290.  
  291.       </form>
  292.  
  293.       &nbsp;
  294.  
  295.       </td>
  296.  
  297.     </tr>
  298.  
  299.     <tr>
  300.  
  301.       <td width="952" height="20" style="border-style: solid; border-width: 1; " bgcolor="#336699" valign="top" colspan="2">&nbsp;</td>
  302.  
  303.     </tr>
  304.  
  305.   </table>
  306.  
  307. </div>
  308.  
  309.  
  310.  
  311. </body>
  312.  
  313. </html>



Install Page 2:
PHP Code: [ Download ] [ Select ]
<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>
 
 
  1. <html>
  2.  
  3.  
  4.  
  5. <head>
  6.  
  7. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  8.  
  9. <title>:: Installation ::</title>
  10.  
  11. </head>
  12.  
  13.  
  14.  
  15. <body>
  16.  
  17.  
  18.  
  19. <?php
  20.  
  21.  
  22.  
  23. //Inputs the user's referer into the variable
  24.  
  25. $ref = $_SERVER['HTTP_REFERER'];
  26.  
  27.  
  28.  
  29. //Writes data to the text file for the database connection
  30.  
  31. $openfile = fopen("../Database/Database_Connection.txt","a");
  32.  
  33. fwrite($openfile,$database_host . "\n");
  34.  
  35. fwrite($openfile,$database_name . "\n");
  36.  
  37. fwrite($openfile,$database_user . "\n");
  38.  
  39. fwrite($openfile,$database_pass . "\n");
  40.  
  41. fclose($openfile);
  42.  
  43.  
  44.  
  45. //Inputs the data from the previous form, into variables
  46.  
  47. $database_host = $_POST['Database_Host'];
  48.  
  49. $database_name = $_POST['Database_Name'];
  50.  
  51. $database_user = $_POST['Database_Username'];
  52.  
  53. $database_pass = $_POST['Database_Password'];
  54.  
  55.  
  56.  
  57. //If the person did not come from Install.php, it redirects them
  58.  
  59. if(empty($ref))
  60.  
  61. {
  62.  
  63. header("location:Install.php");
  64.  
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71. //The following code will delete the 'Install' directory/folder
  72.  
  73. function delete_directory($dirname) {
  74.  
  75.     if (is_dir($dirname))
  76.  
  77.         $dir_handle = opendir($dirname);
  78.  
  79.     if (!$dir_handle)
  80.  
  81.         return false;
  82.  
  83.     while($file = readdir($dir_handle)) {
  84.  
  85.         if ($file != "." && $file != "..") {
  86.  
  87.             if (!is_dir($dirname."/".$file))
  88.  
  89.                 unlink($dirname."/".$file);
  90.  
  91.             else
  92.  
  93.                 delete_directory($dirname.'/'.$file);            
  94.  
  95.         }
  96.  
  97.     }
  98.  
  99.     closedir($dir_handle);
  100.  
  101.     rmdir($dirname);
  102.  
  103.     return true;
  104.  
  105. }
  106.  
  107.  
  108.  
  109. ?>
  110.  
  111.  
  112.  
  113. </body>
  114.  
  115.  
  116.  
  117. </html>
  118.  
  119.  


and the database connection page - config.php:
PHP Code: [ Download ] [ Select ]
<?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");
 
 
 
?>
  1. <?php
  2.  
  3. @$host = file_get_contents($connect_to_database,1);
  4.  
  5. @$account = file_get_contents($connect_to_database,2);
  6.  
  7. @$password = file_get_contents($connect_to_database,3);
  8.  
  9. @$dbname = file_get_contents($connect_to_database,4);
  10.  
  11.  
  12.  
  13. $connect_to_database = fopen("Database_Connection.txt","a");
  14.  
  15.  
  16.  
  17. $connect = mysql_connect($host,$account,$password);
  18.  
  19. $db = mysql_select_db($dbname,$connect)
  20.  
  21. or die("Can't connect to the database");
  22.  
  23.  
  24.  
  25. ?>


How am I to get this to work? Any help on this will be muchly appreciated :wink:
THE BEST THINGS IN LIFE ARE FREE...
JOIN THE MEDIASHARK COMMUNITY TODAY!
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post July 6th, 2005, 12:17 am

  • lostboy
  • Expert
  • Expert
  • No Avatar
  • Joined: Jun 03, 2005
  • Posts: 509
  • Loc: Just north of Toronto
  • Status: Offline

Post July 6th, 2005, 6:22 pm

why don't you just write a php file and include it?

it only has to look like this
PHP Code: [ Download ] [ Select ]
 
<?php
 
$username = "somevalue";
 
$password = "anothervalue";
 
$host         = "localhost"; //or ip
 
$dbname   = "dbname";
 
?>
 
 
  1.  
  2. <?php
  3.  
  4. $username = "somevalue";
  5.  
  6. $password = "anothervalue";
  7.  
  8. $host         = "localhost"; //or ip
  9.  
  10. $dbname   = "dbname";
  11.  
  12. ?>
  13.  
  14.  


and that is trivial to write
Lostboy

Cat, the other other white meat
  • Funny_Fuzz
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jan 18, 2005
  • Posts: 1519
  • Loc: Australia
  • Status: Offline

Post July 6th, 2005, 6:25 pm

That's not an option for me though. The person specifies the values in the "Install" page. And I need those values to be stored somewhere. I would like it to be stored in a text file, but I can't seem to get it to find the correct content of the text file.
THE BEST THINGS IN LIFE ARE FREE...
JOIN THE MEDIASHARK COMMUNITY TODAY!
  • lostboy
  • Expert
  • Expert
  • No Avatar
  • Joined: Jun 03, 2005
  • Posts: 509
  • Loc: Just north of Toronto
  • Status: Offline

Post July 6th, 2005, 6:26 pm

php files are text files...and the adantage is you then don't need to read in those values, just include the file...

but if not, then just use fopen, fread and parse out the lines
Lostboy

Cat, the other other white meat
  • Funny_Fuzz
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jan 18, 2005
  • Posts: 1519
  • Loc: Australia
  • Status: Offline

Post July 6th, 2005, 6:40 pm

Do you know what code will do this?
THE BEST THINGS IN LIFE ARE FREE...
JOIN THE MEDIASHARK COMMUNITY TODAY!
  • lostboy
  • Expert
  • Expert
  • No Avatar
  • Joined: Jun 03, 2005
  • Posts: 509
  • Loc: Just north of Toronto
  • Status: Offline

Post July 6th, 2005, 6:54 pm

try
PHP Code: [ Download ] [ Select ]
 
<?php
 
// Get a file into an array.  In this example we'll go through HTTP to get
 
// the HTML source of a URL.
 
$lines = file('Database_Connection.txt');
 
 
 
// Loop through our array, show HTML source as HTML source; and line numbers too.
 
foreach ($lines as $line_num => $line) {
 
   if ($line_num == 1) { $host     = $line; }
 
   if ($line_num == 2) { $account  = $line; }
 
   if ($line_num == 3) { $password = $line; }
 
   if ($line_num == 4) { $dbname   = $line; }
 
}
 
 
 
?>
  1.  
  2. <?php
  3.  
  4. // Get a file into an array.  In this example we'll go through HTTP to get
  5.  
  6. // the HTML source of a URL.
  7.  
  8. $lines = file('Database_Connection.txt');
  9.  
  10.  
  11.  
  12. // Loop through our array, show HTML source as HTML source; and line numbers too.
  13.  
  14. foreach ($lines as $line_num => $line) {
  15.  
  16.    if ($line_num == 1) { $host     = $line; }
  17.  
  18.    if ($line_num == 2) { $account  = $line; }
  19.  
  20.    if ($line_num == 3) { $password = $line; }
  21.  
  22.    if ($line_num == 4) { $dbname   = $line; }
  23.  
  24. }
  25.  
  26.  
  27.  
  28. ?>
Lostboy

Cat, the other other white meat
  • Funny_Fuzz
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jan 18, 2005
  • Posts: 1519
  • Loc: Australia
  • Status: Offline

Post July 6th, 2005, 8:53 pm

Thanks :D
THE BEST THINGS IN LIFE ARE FREE...
JOIN THE MEDIASHARK COMMUNITY TODAY!
  • Funny_Fuzz
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jan 18, 2005
  • Posts: 1519
  • Loc: Australia
  • Status: Offline

Post July 6th, 2005, 9:02 pm

Hmm... it doesn't seem to be working...
THE BEST THINGS IN LIFE ARE FREE...
JOIN THE MEDIASHARK COMMUNITY TODAY!

Post July 6th, 2005, 9:46 pm

You REALLY SHOULDN'T be storing the database connection information in a .txt file. Text files can be read by a browser, which means anyone who browses to your site and types "Database_Connection.txt" into the browser would have instant access to virtually everything they need to connect to your database.

You really should do as lostboy said and write a .php file, then just include it in your other scripts.

Try this, in Install page 2, replace the following whole section:
PHP Code: [ Download ] [ Select ]
 
//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'];
 
 
  1.  
  2. //Writes data to the text file for the database connection
  3.  
  4. $openfile = fopen("../Database/Database_Connection.txt","a");
  5.  
  6. fwrite($openfile,$database_host . "\n");
  7.  
  8. fwrite($openfile,$database_name . "\n");
  9.  
  10. fwrite($openfile,$database_user . "\n");
  11.  
  12. fwrite($openfile,$database_pass . "\n");
  13.  
  14. fclose($openfile);
  15.  
  16.  
  17.  
  18. //Inputs the data from the previous form, into variables
  19.  
  20. $database_host = $_POST['Database_Host'];
  21.  
  22. $database_name = $_POST['Database_Name'];
  23.  
  24. $database_user = $_POST['Database_Username'];
  25.  
  26. $database_pass = $_POST['Database_Password'];
  27.  
  28.  

With:
PHP Code: [ Download ] [ Select ]
 
//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'];
 
 
 
//Writes data to the text file for the database connection
 
$openfile = fopen("../Database/Database_Connection.php","a");
 
fwrite($openfile,'<?php\n$database_host = '.$database_host . ";\n");
 
fwrite($openfile,'$database_name = '.$database_name . ";\n");
 
fwrite($openfile,'$database_user = '.$database_user . ";\n");
 
fwrite($openfile,'$database_pass = '.$database_pass . ';\n?>\n');
 
fclose($openfile);
 
 
  1.  
  2. //Inputs the data from the previous form, into variables
  3.  
  4. $database_host = $_POST['Database_Host'];
  5.  
  6. $database_name = $_POST['Database_Name'];
  7.  
  8. $database_user = $_POST['Database_Username'];
  9.  
  10. $database_pass = $_POST['Database_Password'];
  11.  
  12.  
  13.  
  14. //Writes data to the text file for the database connection
  15.  
  16. $openfile = fopen("../Database/Database_Connection.php","a");
  17.  
  18. fwrite($openfile,'<?php\n$database_host = '.$database_host . ";\n");
  19.  
  20. fwrite($openfile,'$database_name = '.$database_name . ";\n");
  21.  
  22. fwrite($openfile,'$database_user = '.$database_user . ";\n");
  23.  
  24. fwrite($openfile,'$database_pass = '.$database_pass . ';\n?>\n');
  25.  
  26. fclose($openfile);
  27.  
  28.  


Again, you have to assign the variable:
PHP Code: [ Download ] [ Select ]
$database_name = $_POST['Database_Name'];

before you can use it:
PHP Code: [ Download ] [ Select ]
fwrite($openfile,'$database_name = '.$database_name . ";\n");


Providing there are no other errors in your script, this will create a php file which can then just be included in your database connection file, like this:

PHP Code: [ Download ] [ Select ]
<?php
 
require("../Database/Database_Connection.php");
 
 
 
$connect = mysql_connect($database_host,$database_user,$database_pass);
 
$db = mysql_select_db($database_name,$connect)
 
or die("Can't connect to the database");
 
 
 
?>
  1. <?php
  2.  
  3. require("../Database/Database_Connection.php");
  4.  
  5.  
  6.  
  7. $connect = mysql_connect($database_host,$database_user,$database_pass);
  8.  
  9. $db = mysql_select_db($database_name,$connect)
  10.  
  11. or die("Can't connect to the database");
  12.  
  13.  
  14.  
  15. ?>


You seem to like to try to use variables before you have assigned them. This doesn't work in php.
For instance, in your database connect file, you are trying to use the function "file_get_contents" on the file pointer "$connect_to_database", yet you don't even open the file until after you try to read it. PHP is not a stateless language, meaning you have to declare variables/file pointers/database connections BEFORE you try to use them.

An very simple example:
PHP Code: [ Download ] [ Select ]
<?php
 
echo $a;
 
 
 
$a = "Something";
 
?>
  1. <?php
  2.  
  3. echo $a;
  4.  
  5.  
  6.  
  7. $a = "Something";
  8.  
  9. ?>


The above script will print nothing, because I haven't defined $a before I try to echo it.

Do you see what I'm getting at?

Anyway, Hope this helps.
  • Funny_Fuzz
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jan 18, 2005
  • Posts: 1519
  • Loc: Australia
  • Status: Offline

Post July 7th, 2005, 12:55 am

Thanks a heap Sos! That really helped!
THE BEST THINGS IN LIFE ARE FREE...
JOIN THE MEDIASHARK COMMUNITY TODAY!
  • Funny_Fuzz
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jan 18, 2005
  • Posts: 1519
  • Loc: Australia
  • Status: Offline

Post July 7th, 2005, 6:54 pm

One more thing though. When the person puts in nothing/null in the password field, how do I make it set the variable $database_password to __ as a string or whatever, so that it doesn't think it's meant to put nothing in the variable? Get what I'm saying?

__ will set NULL/nothing to the variable. I want to stop it from doing that, so it doesn't give me errors when the person doesn't type anything in the previous form.

Please help. I'm behind schedule!
THE BEST THINGS IN LIFE ARE FREE...
JOIN THE MEDIASHARK COMMUNITY TODAY!
  • lostboy
  • Expert
  • Expert
  • No Avatar
  • Joined: Jun 03, 2005
  • Posts: 509
  • Loc: Just north of Toronto
  • Status: Offline

Post July 7th, 2005, 7:45 pm

a little check is all you need to stop it from being empty

if (empty($_POST['password']))
{
echo "please enter a password";
}
Lostboy

Cat, the other other white meat
  • Funny_Fuzz
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jan 18, 2005
  • Posts: 1519
  • Loc: Australia
  • Status: Offline

Post July 7th, 2005, 11:11 pm

Thanks!
THE BEST THINGS IN LIFE ARE FREE...
JOIN THE MEDIASHARK COMMUNITY TODAY!

Post Information

  • Total Posts in this topic: 13 posts
  • Users browsing this forum: No registered users and 219 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© Unmelted Enterprises 1998-2009. Driven by phpBB © 2001-2009 phpBB Group.