Solved

PHP Parse error:  syntax error, unexpected $end in C:\inetpub\wwwroot\WebDate\install.php on line 417

Posted on 2010-08-26
11
2,903 Views
Last Modified: 2012-05-10
PHP Parse error:  syntax error, unexpected $end in C:\inetpub\wwwroot\WebDate\install.php on line 417

<?php

require_once('smartway/lib/system.lib');
set_magic_quotes_runtime(0);

if (!$step) $step = 1;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>webDate Installation</title>
	<link rel="stylesheet" type="text/css" href="install/style.css">
</head>

<body marginheight="0" marginwidth="0" topmargin="0" leftmargin="0">
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td><img src="install/images/logo.gif" alt="" border="0"></td>
			<td background="install/images/bg_top.gif" width="100%" align="right" style="padding:10px;" valign="bottom"></td>
			<td><img src="install/images/border_top.gif" width="26" height="91" alt="" border="0"></td>
		</tr>
	</table>
	<center>
	<br><br>
<?php

if (file_exists('installer.done'))
{
echo<<<END
<p><b>Since webDate has already been installed here, the installer has disabled
itself</b>.</p>

<p>Should you need to redo the installation process, you will need to delete
the file named <i>installer.done</i>.</p>
END;

?>
	<br><br>
	</center>
	<table width="100%" border="0" height="50">
	  <tr>
	  	<td colspan="2"><hr noshade size="1" color=C0C0C0></td>
	  </tr>
	  <tr>
	    <td valign="top" width="35"><a href="http://www.webscribble.com/support.shtml" target="_BLANK"><font color="#669966">[<img src="install/images/p.gif" width="14" height="14" border="0">]</font></a></td>
	    <td height="22" align="left"><a href="http://www.webscribble.com/support.shtml" target="_BLANK"><font color="#999999">Contact us with any questions</font></a></td>
	  </tr>
	  <tr>
	    <td colspan="2"><hr noshade size="1" color=C0C0C0></td>
	  </tr>
	</table>
	<br>
	<table width="100%" border="0">
	  <tr>
	    <td>webDate Installation</td>
	    <td align="right">&copy; Web Scribble Solutions, Inc. 2002-2005</td>
	  </tr>
	</table>
	<br>
</body>
</html>
<?
exit;
}

switch ($step)
{
  case 2:
    if (!$db_name)
      step('<p><b>You must specify a database name</b></p>');
  
    // Try to establish a database connection.
    $db = @mysql_connect($db_host, $db_user, $db_password);
    if (!$db)
    {
      $mysql_err = mysql_error();
      step("<p><b>Error: Could not connect to the database server. Please check your settings and
        try again. The error returned was: $mysql_err</b></p>", 1);
    }
    if (@mysql_select_db($db_name, $db))
      $db_status = "<p><b>Database $db_name successfully located.</b></p>";
    else if (@mysql_create_db($db_name, $db))
    {
      if (@mysql_select_db($db_name, $db))
        $db_status = "<p><b>Database $db_name successfully created.</b></p>";
      else
        step("<p><b>Database $db_name successfully created, but could not be selected.</b></p>");
    }
    else
      step("Error: Connected to the database server, but could not locate or create database $db_name");
    $errors = run_install_sql_script('install/tables', $db);
    if ($errors)
      step("<p><b>Table creation failed with the following error(s)</b>:</p><p>$errors</p>");

    // Save the DB configuration.
    $fp = @fopen('smartway/conf/conf.xml', 'r');
    if (!$fp)
      step("<p><b>Error opening the configuration file. Please ensure that you have uploaded everything
        correctly and have set the proper permissions.</b></p>", 1);
    $buffer = @fread($fp, filesize('smartway/conf/conf.xml'));
    
    $buffer = str_replace('your_db_host', $db_host, $buffer);
    $buffer = str_replace('your_db_username', $db_user, $buffer);
    $buffer = str_replace('your_db_password', $db_password, $buffer);
    $buffer = str_replace('your_db_name', $db_name, $buffer);

    $fp = @fopen('smartway/conf/conf.xml', 'w');
    if (!$fp)
      step('<p><b>Error modifying the configuration file. Please ensure that you have uploaded everything
        correctly and have set the proper permissions.</b></p>', 1);
    if (!@fwrite($fp, $buffer))
      step('<p><b>Error saving the configuration file. Please check that the disk is not full.</b></p>');
    fclose($fp);
    step($db_status, 2);
    break;
  case 3:

    // Verify the form data.
    if (!$serialnumber)
      $errors_string .= "  <li>You must enter a serial number.</li>\n";
    if (!$admin_name)
      $errors_string .= "  <li>You must enter an admin login name.</li>\n";
    if (!$admin_password || !$admin_password2)
      $errors_string .= "  <li>You must fill in both password fields.</li>\n";
    if ($admin_password != $admin_password2)
      $errors_string .= "  <li>Both password fields must match.</li>\n";
    if (!$root_host)
      $errors_string .= "  <li>You must enter a base URL.</li>\n";
    if (!$site_title)
      $errors_string .= "  <li>You must enter a Site Title.</li>\n";
    if (!preg_match('!^http://!i', $root_host))
      $errors_string .= "  <li>Your base URL must begin with &quot;http://&quot;.</li>\n";
    if (!$admin_email)
      $errors_string .= "  <li>You must enter an admin email address.</li>\n";
    if (!preg_match('/(?:\S+)\@(?:\S+)/', $admin_email))
      $errors_string .= "  <li>Your email address does not appear to be of a valid format.</li>\n";

    if ($errors_string)
      step("<p><b>We could not proceed because due to the following error(s):
<ol>
$errors_string
</ol></b></p>\n", 2);

    // Save the DB configuration -- conf.xml.
    $fp = @fopen('smartway/conf/conf.xml', 'r+');
    if (!$fp)
      step("<p><b>Error modifying the configuration file. Please ensure that you have uploaded everything
        correctly and have set the proper permissions.</b></p>", 2);
    $buffer = @fread($fp, filesize('smartway/conf/conf.xml'));

    $buffer = str_replace('#your_serial_number"><', "#your_serial_number\">$serialnumber<", $buffer);
    $buffer = str_replace('>webscribble<', ">$admin_name<", $buffer);
    $buffer = str_replace('c2NyaWJibGU=', base64_encode($admin_password), $buffer);
    $buffer = str_replace('your_email', $admin_email, $buffer);

    @ftruncate($fp, 0);
    fseek($fp, SEEK_SET, 0);
    if (!@fwrite($fp, $buffer))
      step("<p><b>Error saving the smartway/conf/conf.xml configuration file. Please check that the disk is not full.</b></p>", 2);
    fclose($fp);
    
    // Save the DB configuration -- sitesettings/conf.xml.
    $fp = @fopen('smartway/plug-ins/sitesettings/conf.xml', 'r+');
    $buffer = @fread($fp, filesize('smartway/plug-ins/sitesettings/conf.xml'));

    $buffer = str_replace('your_website_url', $root_host, $buffer);
    $buffer = str_replace('your_site_title', $site_title, $buffer);

    @ftruncate($fp, 0);
    fseek($fp, SEEK_SET, 0);
    if (!@fwrite($fp, $buffer))
      step("<p><b>Error saving the smartway/plug-ins/sitesettings/conf.xml configuration file. Please check that the disk is not full.</b></p>", 2);
    fclose($fp);
    
    $fp = @fopen("installer.done", "x+");
    if(!$fp)
      step("<p><b>Error creating lock file. Please check your permissions.</b></p>
		<p>This is not, in itself, a fatal error; however, it leaves you vulnerable to someone running install.php behind
		your back and overwriting your information. Therefore, you should delete install.php <b>as soon as possible</b>.</p>", 3);
		
    step("<p>webDate is now successfully installed!</p>", 3);
    fclose($fp);
    break;
    
  default:  // Assume step 1.
    if (!$db_host)
      $db_host = "localhost";
      
    // Check permissions.
    $bad_perm_files .= ok_perms('smartway/');
    $bad_perm_files .= ok_perms('smartway/conf/');
    $bad_perm_files .= ok_perms('smartway/conf/conf.xml');
    $bad_perm_files .= ok_perms('photos/');
    $bad_perm_files .= ok_perms('videos/');

	$bad_perm_files .= ok_perms('images/');
	$bad_perm_files .= ok_perms('templates/');
	$bad_perm_files .= ok_perms('templates/forms/');
	$bad_perm_files .= ok_perms('templates/mail/');

    if ($bad_perm_files)
    {
      echo<<<END
<p><b>Preliminary tests have failed. The directories and/or files listed below
do not have sufficient permissions. Please CHMOD them and all contents to 0777 and re-run this script.</b></p>

<ul>
$bad_perm_files
</ul>
<p align="center">
<a href="$PHP_SELF">Retry the script</a></p>

END;
      exit;
    }
    step();
}

function ok_perms($file)
{
  return is_readable($file) && is_writable($file) ? '' : "<li>$file</li>";
}

function step($error = 'Welcome to the webDate installer!<br>', $step_num = 1)
{
  global $root_host;

  switch ($step_num)
  {
    case 2:
      $root_host = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
      if ($root_host{strlen($root_host) - 1} != '/')
        $root_host .= '/';
      echo<<<END
<center>
<font color="red"><b>$error</b></font><br>
<table border="0" cellspacing="0" cellpadding="1" bgcolor="#000000">
  <tr>
    <td>
      <table border="0" cellspacing="4" cellpadding="4" bgcolor="C7D5F1" width="350">
        <form action="{$_SERVER['PHP_SELF']}" action="post">
          <tr>
            <td>
              <table border="0" cellspacing="2" cellpadding="2" bgcolor="C7D5F1">
                <tr>
                  <td colspan="2">
					<p>Your tables have been created and populated successfully. Now, all that we
					need to do is to configure a few important variables.</p>
				  </td>
				</tr>
				<input type="hidden" name="step" value="3" />
			    <tr>
			      <td width="250">Your webDate serial number:</td>
			      <td><input type="text" name="serialnumber" /></td>
			    </tr>
			    <tr>
			      <td width="250">Base webDate URL:</td>
			      <td><input type="text" name="root_host" value="$root_host" /></td>
			    </tr>
			    <tr>
			      <td width="250">Title of your website:</td>
			      <td><input type="text" name="site_title" value="webDate" /></td>
			    </tr>
			    <tr>
			      <td width="250">Admin login name:</td>
			      <td><input type="text" name="admin_name" /></td>
			    </tr>
			    <tr>
			      <td width="250">Admin password:</td>
			      <td><input type="password" name="admin_password" /></td>
			    </tr>
			    <tr>
			      <td width="250">Confirm admin password:</td>
			      <td><input type="password" name="admin_password2" /></td>
			    </tr>
			    <tr>
			      <td width="250">Admin email address:</td>
			      <td><input type="text" name="admin_email" /></td>
			    </tr>
			  	<tr>
				  <td colspan="2" align="center"><input type="image" value="Proceed" src="install/images/proceed.gif" /></td>
				</tr>
			  </table>
            </td>
          </tr>
        </form>
      </table>
    </td>
  </tr>
</table>
</center>
END;
      break;
    case 3:
      echo<<<END
$error
<p>You may now log into the <a href="{$root_host}smartway/">webDate
administrative area</a> and continue to customize your site.</p>

<p>You may now delete &quot;install.php&quot;.</p>
END;
    break;
    default:
      echo<<<END
<center>
<font color="red"><b>$error</b></font><br>
<table border="0" cellspacing="0" cellpadding="1" bgcolor="#000000">
  <tr>
    <td>
      <table border="0" cellspacing="4" cellpadding="4" bgcolor="C7D5F1" width="350">
        <form action="{$_SERVER['PHP_SELF']}" action="post">
          <tr>
            <td>
              <table border="0" cellspacing="2" cellpadding="2" bgcolor="C7D5F1">
                <tr>
                  <td colspan="2">
					<p>In order to set up the backend properly, we need your database
					information.</p>
				  </td>
				</tr>
				<input type="hidden" name="step" value="2" />
			    <tr>
			      <td width="250">Database host:<br />
			        <span class="small">(IP address is OK)</span></td>
			      <td><input type="text" name="db_host" value="localhost" /></td>
			    </tr>
			    <tr>
			      <td>Database user name:</td>
			      <td><input type="text" name="db_user" /></td>
			    </tr>
			    <tr>
			      <td>Database password:</td>
			      <td><input type="password" name="db_password" /></td>
			    </tr>
			    <tr>
			      <td>Database name:</td>
			      <td><input type="text" name="db_name" /></td>
			    </tr>
			    <tr>
			      <td colspan="2" align="center"><input type="image" value="Proceed" src="install/images/proceed.gif" /></td>
				</tr>
			  </table>
            </td>
          </tr>
        </form>
      </table>
    </td>
  </tr>
</table>
</center>
END;
  }
?>
	<br><br>
	</center>
	<table width="100%" border="0" height="50">
	  <tr>
	  	<td colspan="2"><hr noshade size="1" color=C0C0C0></td>
	  </tr>
	  <tr>
	    <td valign="top" width="35"><a href="http://www.webscribble.com/support.shtml" target="_BLANK"><font color="#669966">[<img src="install/images/p.gif" width="14" height="14" border="0">]</font></a></td>
	    <td height="22" align="left"><a href="http://www.webscribble.com/support.shtml" target="_BLANK"><font color="#999999">Contact us with any questions</font></a></td>
	  </tr>
	  <tr>
	    <td colspan="2"><hr noshade size="1" color=C0C0C0></td>
	  </tr>
	</table>
	<br>
	<table width="100%" border="0">
	  <tr>
	    <td>webDate Installation</td>
	    <td align="right">&copy; Web Scribble Solutions, Inc. 2002-2005</td>
	  </tr>
	</table>
	<br>
</body>
</html>
<?
  exit;
}

// Run a set of queries, collecting errors for each.
function run_queries($queries_string, $db)
{
  $errors = '';

  $queries = split(';', $queries_string);
  reset($queries);
  foreach ($queries as $query)
  {
    $query = trim($query);
    if (empty($query))
      continue;
    mysql_query($query, $db);
    $this_error = mysql_error($db);
    if ($this_error)
      $errors .= "$this_error<br />";
  }
  return $errors;
}

function run_install_sql_script($file, $db)
{
  global $step;
  
  $fp = @fopen($file.'.sql', 'r');
  if (!$fp)
    step("<p><b>Error opening an install SQL script. Please ensure that you have uploaded everything
      correctly and have set the proper permissions (at least 755 for the &quot;install&quot; directory and
      644 for the files inside that directory).</b></p>", --$step);

  $script = fread($fp, filesize($file.'.sql'));
  fclose($fp);
  return run_queries($script, $db);
}
?>

Open in new window

0
Comment
Question by:omegalove
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 9

Accepted Solution

by:
Snarfles earned 500 total points
ID: 33538772
There are so many things wrong with that code.

You need to go through and do a few things.

Start by making sure that you open your php code with <?php even if your current server configuration is setup to allow this you will at some point run into one that doesn't and you will give yourself a headache.

Also enclose blocks of code using the openeing and closing curly brackets { }

This is where you are stuffed up as there is code seemingly all over the place.

That error message means exactly that. The parser doesn't know what is what because it doesn't know when you if statements end and start.
0
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 33538785
One thing that sticks out to me is that you have one curly bracket on line 226 that opens a statement { and the closing one spans an ending ?> (line 354) and the next beginning one <? (line 379). That will generate errors for sure.
0
 

Author Comment

by:omegalove
ID: 33538789
download webdate and try it.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 2

Expert Comment

by:Nol888
ID: 33539054
On lines 63 and 379 you have short open tags ("<?") rather than the full "<?php". If your server doesn't have that setting enabled (disabled by default on newer php's iirc) then it will generate a syntax error.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 33539640
I don't know if this can be a right puctuation, but at line 206 you have an empty line:

<a href="$PHP_SELF">Retry the script</a></p>

END;

Using "here document" syntax requires that END terminator appear on a line with just a semicolon. no extra whitespace. Technically, here you don't have a whitespace but a return character. I repeat: I don't know if this can be a problem, but you could try to delete the blank line...

Hope this helps
0
 
LVL 2

Expert Comment

by:Nol888
ID: 33541276
The only syntax issue with the code is the use of short-open tags.
0
 

Author Closing Comment

by:omegalove
ID: 33547521
awesome
0
 
LVL 9

Expert Comment

by:Snarfles
ID: 33547603
No disrespect to Nol888 but how is his answer of short open tags better than my first answer that included saying that you should not use short open tags?
0
 

Author Comment

by:omegalove
ID: 33547647
let me post the question again, my excuse.
0
 
LVL 2

Expert Comment

by:Nol888
ID: 33555474
I wish to dispute the reassignment. From that answer, it's not clear to see what exactly solved the issue, plus the author of the post made it clear that the PHP open tags were not his/her main solution. Instead they seemed to emphasize the use of (unnecessary) brackets to group code as the solution.

Also their explanation of the error message is incorrect, PHP throws the error when it was expecting more code (to finish a block, etc) but instead found EoF.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question