Setup Script.. Keep getting unexpected T_CONSTANT_ENCAPSED..
Posted: Mon Jul 18, 2005 11:09 pm
I've written a php setup script for my system, and it's supposed to set up a database table, make .htaccess & .htpasswd files, and create a config.php file. I started writing PHP a few days ago, so I'm quite new in the "game"
It works like this: The one running the setup.php fills in information and click the submit button, which sends the information entered to setup2.php, which is the script making the files and creating the db table... But when the setup2-script is running, it gets an error at line 72. Line 72 is in the middle of my database query. I can't see why I'm getting this annoying error;
setup.php
and the error generating file, setup2.php
Hope somebody can see my mistake... Have a nice day...
... If someone could tell me what's wrong I would be very gratefull... The codes is posted below... Thanks in advanceParse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /usr/home/web/wno14743/hap/setup2.php on line 72
setup.php
Code: Select all
CSS AND STUFF CROPPED
<body>
<form name="e;form1"e; method="e;post"e; action="e;setup2.php"e;>
<table width="e;610"e; border="e;0"e; align="e;center"e; cellpadding="e;0"e; cellspacing="e;0"e;>
<tr>
<td colspan="e;4"e; class="e;part"e;><div align="e;right"e;>setup: <span class="e;style3"e;>del 1/3</span> </div></td>
</tr>
<tr>
<td colspan="e;4"e; class="e;part"e;>.system</td>
</tr>
<tr>
<td class="e;fyll"e;>&nbsp;</td>
<td class="e;fyll"e;>&nbsp;</td>
<td valign="e;top"e; class="e;fyll"e;>&nbsp;</td>
<td class="e;fyll"e;>&nbsp;</td>
</tr>
<tr>
<td class="e;fyll"e;><p align="e;right"e;>Brukernavn</p>
</td>
<td class="e;fyll"e;>&nbsp;</td>
<td valign="e;top"e; class="e;fyll"e;><input type="e;text"e; name="e;user"e;></td>
<td class="e;fyll"e;>Brukernavn for &quot;Samler&quot;-systemet</td>
</tr>
<tr>
<td class="e;fyll"e;><div align="e;right"e;>Passord</div></td>
<td class="e;fyll"e;>&nbsp;</td>
<td class="e;fyll"e;><input type="e;text"e; name="e;pass"e;></td>
<td class="e;fyll"e;>Passord for &quot;Samler&quot;-systemet </td>
</tr>
<tr>
<td class="e;fyll"e; valign="e;top"e;><div align="e;right"e;>URL-Adresse til rot </div></td>
<td class="e;fyll"e;>&nbsp;</td>
<td class="e;fyll"e; valign="e;top"e;><input type="e;text"e; name="e;url"e;></td>
<td class="e;fyll"e;>Adressen til mappen du skal ha &quot;Samler&quot;. I denne formen: http://doffer.net/samler/</td>
</tr>
<tr>
<td valign="e;top"e; class="e;fyll"e;><div align="e;right"e;>System-Adresse til rot </div></td>
<td class="e;fyll"e;>&nbsp;</td>
<td valign="e;top"e; class="e;fyll"e;><input type="e;text"e; name="e;path"e;></td>
<td class="e;fyll"e;>Serveradressen til mappen du skal ha &quot;Samler&quot;. I denne formen: /home/web/wno14743/samler/</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="e;4"e; class="e;part"e;>.database</td>
</tr>
<tr>
<td class="e;fyll"e;>&nbsp;</td>
<td class="e;fyll"e;>&nbsp;</td>
<td class="e;fyll"e;>&nbsp;</td>
<td class="e;fyll"e;>&nbsp;</td>
</tr>
<tr>
<td class="e;fyll"e; width="e;200"e;><div align="e;right"e;>Server-URL</div></td>
<td class="e;fyll"e; width="e;10"e;><div align="e;right"e;></div></td>
<td class="e;fyll"e; width="e;151"e;><input type="e;text"e; name="e;db_host"e;></td>
<td class="e;fyll"e; width="e;271"e;>Adressen til databaseserveren <br>I denne formen: db.doffer.net</td>
</tr>
<tr>
<td class="e;fyll"e;><div align="e;right"e;>DatabaseNavn</div></td>
<td class="e;fyll"e;><div align="e;right"e;></div></td>
<td class="e;fyll"e;><p>
<input type="e;text"e; name="e;db_name"e;>
</p>
</td>
<td class="e;fyll"e;>Navnet p&aring; databasen du vil bruke </td>
</tr>
<tr>
<td class="e;fyll"e;><div align="e;right"e;>Brukernavn</div></td>
<td class="e;fyll"e;>&nbsp;</td>
<td class="e;fyll"e;><input type="e;text"e; name="e;db_user"e;></td>
<td class="e;fyll"e;>Brukernavn for databasen </td>
</tr>
<tr>
<td class="e;fyll"e;><div align="e;right"e;>Passorde </div></td>
<td class="e;fyll"e;>&nbsp;</td>
<td class="e;fyll"e;><input type="e;text"e; name="e;db_pass"e;></td>
<td class="e;fyll"e;>Passord til databasen </td>
</tr>
<tr>
<td class="e;fyll"e;><div align="e;right"e;>Tabell</div></td>
<td class="e;fyll"e;>&nbsp;</td>
<td class="e;fyll"e; valign="e;top"e;><input type="e;text"e; name="e;db_table"e;></td>
<td class="e;fyll"e;>Navnet du &oslash;nsker p&aring; tabellen for Samler </td>
</tr>
<tr>
<td class="e;fyll"e;><div align="e;right"e;></div></td>
<td class="e;fyll"e; rowspan="e;2"e;>&nbsp;</td>
<td class="e;fyll"e;>&nbsp;</td>
<td class="e;fyll"e;>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="e;submit"e; name="e;Submit"e; value="e;Submit"e;></td>
SOME MORE CROPPEDCode: Select all
<?
//Systemvariabler
$user = $_POST['user'];
$password = $_POST['pass'];
$pass = crypt($password);
$url = $_POST['url'];
$path = $_POST['path'];
//Databasevariabler
$db_host = $_POST['db_host'];
$db_name = $_POST['db_name'];
$db_table = $_POST['db_table'];
$db_user = $_POST['db_user'];
$db_pass = $_POST['db_pass'];
//Opprett .htaccess (ta bort kommentartegnet når setup-filen er ferdig)
$data = "AuthName \"Samler - Admin\"
AuthType Basic
AuthUserFile ".$path."
require valid-user";
$file = "admin/.htaccess";
if (!$file_handle = fopen($file,"a")) { echo "Cannot open file"; }
if (!fwrite($file_handle, $data)) { echo "Cannot write to file"; }
echo ".htaccess-fil er opprettet";
fclose($file_handle);
//Opprett .htpasswd (ta bort kommentartegnet når setup-filen er ferdig)
$data = "$user:$pass";
$file = ".htpasswd";
if (!$file_handle = fopen($file,"a")) { echo "Cannot open file"; }
if (!fwrite($file_handle, $data)) { echo "Cannot write to file"; }
echo ".htaccess-fil er opprettet";
fclose($file_handle);
//Opprett config.php (ta bort kommentartegnet når setup-filen er ferdig)
$data = "<?php
//Database-variabler
\$db_host = \"".$db_host."\";
\$db_user = \"".$db_user."\";
\$db_pass = \"".$db_pass."\";
\$db_name = \"".$db_name."\";
\$db_table = \"".$db_table."\";
//Andre variabler
$root = \"".$url."\";
?>";
$file = "config.php";
if (!$file_handle = fopen($file,"a")) { echo "Cannot open file"; }
if (!fwrite($file_handle, $data)) { echo "Cannot write to file"; }
echo "config-fil er opprettet";
fclose($file_handle);
//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("$db_host","$db_user","$db_pass"); //(host, username, password)
//specify database ** EDIT REQUIRED HERE **
mysql_select_db("$db_name") or die("Unable to select database"); //select which database we're using
// Build SQL Query
$query = 'CREATE TABLE `test` ('
. ' `utgitt` INT(11) NOT NULL, '
. ' `album` VARCHAR(100), '
. ' `artist` VARCHAR(100), '
. ' `bilde` VARCHAR(150), '
. ' `om` LONGTEXT NOT NULL, '
. ' `vurdering` TINYINT(4) DEFAULT ''0'' NOT NULL\,'
. ' `forbokstav` TINYTEXT NOT NULL, '
. ' `type` ENUM(''1'',''2'',''3'') DEFAULT ''1'' NOT NULL, '
. ' `isbn` MEDIUMTEXT NOT NULL, '
. ' `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,'
. ' PRIMARY KEY (`id`)'
. ' )';
mysql_query($query) or die("Couldn't execute query");
?>