Page 1 of 1

Help with PHP script/fwrite

Posted: Mon Jul 26, 2010 9:23 pm
by GeezerOlds
Hello everyone,

I'm new to this board as well as PHP/mySQL itself. I'm building one of my first dynamic websites for a local used car dealership. What I attempted to do was write a script that would allow each car on the dealership's lot to be listed along with the details of each specific model; I learned quickly that I am not able to write a script as elaborate as I'd like at my current skill level :) .

I ended up purchasing this script. After following the initial unpacking/chmod777 requirements, I go to run the setup.php page as instructed and receive this (very vague) error: Parse error: parse error in C:\wamp\www\cars\AutoClassifiedScript\setup.php on line 190. I've checked at line 190 and this is the code (starting at line 188):

Code: Select all

          fwrite ($fp, '<?php
');
          fwrite ($fp, '$dbhost = \'' . $_POST[dbhost] . '\';
');
          fwrite ($fp, '$dbuser = \'' . $_POST[dbuser] . '\';
');
          fwrite ($fp, '$dbpass = \'' . $_POST[dbpass] . '\';
');
          fwrite ($fp, '$session_path = \'' . $_POST[session_path] . '\';

');
          fwrite ($fp, '// To turn ON demo mode change the value below to 1
');
          fwrite ($fp, '// To turn OFF demo mode change the value below to 0
');
          fwrite ($fp, '$demo = 0;

');
          fwrite ($fp, '// To disable the style overrides used by the Color Options
');
          fwrite ($fp, '// feature in the control panel set the value below to 1
');
          fwrite ($fp, '$override = 0;

');
          fwrite ($fp, '?>
I'm not sure what is wrong with the syntax of the fwrite command. I've sent a support request to the group that wrote the script but I have yet to receive a response.

As I said, I'm very new to PHP and I hope that I'm not asking a very dumb question, please forgive me if I am :wink: . I certainly appreciate any assistance!

Re: Help with PHP script/fwrite

Posted: Mon Jul 26, 2010 10:19 pm
by requinix
Can you post lines 1-200?

Re: Help with PHP script/fwrite

Posted: Mon Jul 26, 2010 10:38 pm
by GeezerOlds
Sure, here is 1-200:

Code: Select all

<?
  require 'admin/cp-includes/inc-confdata.php';
  require 'admin/cp-includes/inc-branding.php';
  require 'admin/cp-includes/inc-functions.php';

  $page_titl = 'Setup Wizard';
  $page_desc = '';
  $page_keys = '';
  $page_path = 'admin/';
  require 'admin/cp-includes/inc-wheader.php';
  $dirset = array ('images', 'enlarge', 'thumbs', 'temp', 'admin/cp-thumbs');
  $confdata = 'admin/cp-includes/inc-confdata.php';
  $makes = 'Acura
Aston Martin
Audi
Bentley
BMW
Buick
Cadillac
Chevrolet
Chrysler
Dodge
Ferrari
Ford
GMC
Honda
Hummer
Hyundai
Infiniti
Isuzu
Jaguar
Jeep
Kia
Lamborghini
Land Rover
Lexus
Lincoln
Lotus
Maserati
Maybach
Mazda
Mercedes-Benz
Mercury
MINI
Mitsubishi
Nissan
Oldsmobile
Plymouth
Pontiac
Porsche
Rolls-Royce
Saab
Saturn
Scion
Subaru
Suzuki
Toyota
Volkswagen
Volvo';
  $categories = 'Passenger Car
Luxury Car
Sports Car
Sport Utility Vehicle
Van/Minivan
Pickup Truck';
  $conditions = 'New
Pre-Owned';
  $transmissions = 'Automatic
Manual
Tiptronic';
  $fuels = 'Biodiesel
CNG
Diesel
Electric
Ethanol-FFV
Gasoline
Hybrid-Electric
Steam
Other';
  $status = 'Available
Sale Pending
Sold';
  echo '
<div id=\'setup_content\'>
	
	';
  if (!($_POST[step]))
  {
    echo '	
		<p><strong>Welcome to the ';
    echo $product;
    echo ' ';
    echo $version;
    echo ' Setup Wizard.</strong></p>
		
		<p>This Setup Wizard will guide you through the installation of the ';
    echo $product;
    echo ' 
		application. If you have any questions during the setup process please refer 
		to the installation section of the ';
    echo $product;
    echo ' user\'s manual.</p>
		
		<p><form action=\'';
    echo $_SERVER[PHP_SELF];
    echo '\' method=\'post\'>
		<input type=\'submit\' value=\'Continue\'/>
		<input type=\'hidden\' name=\'step\' value=\'1\'/>
		</form></p>
	
	';
  }

  if ($_POST[step] == 1)
  {
    foreach ($dirset as $dir)
    {
      if (is_dir ($dir))
      {
        if (!(is_writable ($dir)))
        {
          $error .= 'You must change the <b>' . $dir . '</b> directory\'s permissions to 777.<br/>';
          continue;
        }

        continue;
      }
      else
      {
        $error .= 'The <b>' . $dir . '</b> directory was not found.<br/>';
        continue;
      }
    }

    if (is_file ($confdata))
    {
      if (!(is_writable ($confdata)))
      {
        $error .= 'You must change the <b>' . $confdata . '</b> file\'s permissions to 777.<br/>';
      }
      else
      {
        $data = implode ('', file ($confdata));
        if (substr (trim ($data), 0, 5) == '<?php')
        {
          $error .= '' . $product . ' has already been installed in this directory.  To reinstall ' . $product . '
					in this directory you must delete the contents of the <b>' . $confdata . '</b> file.<br/>';
        }
      }
    }
    else
    {
      $error .= 'The <b>' . $confdata . '</b> file was not found.<br/>';
    }

    if ($error)
    {
      echo '<p>Directory structure check and file check results:</p>';
      echo '<div id=\'msg-error\'>' . $error . '</div>';
      echo '<p>Please correct the errors above and click your browser\'s \'Refresh\' button.</p>';
    }
    else
    {
      $_POST[step] = 2;
    }
  }

  if ($_POST[step] == 2)
  {
    if ($_POST[submit])
    {
      if (!(trim ($_POST[dbhost])))
      {
        $error .= 'The <b>Database Host</b> field was left blank.<br/>';
      }

      if (!(trim ($_POST[dbname])))
      {
        $error .= 'The <b>Database Name</b> field was left blank.<br/>';
      }

      if (!($error))
      {
        ($link = @mysql_connect ($_POST[dbhost], $_POST[dbuser], $_POST[dbpass]) OR $error = 'Database connection failed: ' . mysql_error ());
        if (!($error))
        {
          $fp = fopen ($confdata, 'w');
          fwrite ($fp, '<?php
');
          fwrite ($fp, '$dbhost = \'' . $_POST[dbhost] . '\';
');
          fwrite ($fp, '$dbuser = \'' . $_POST[dbuser] . '\';
');
          fwrite ($fp, '$dbpass = \'' . $_POST[dbpass] . '\';
');
          fwrite ($fp, '$session_path = \'' . $_POST[session_path] . '\';

');
          fwrite ($fp, '// To turn ON demo mode change the value below to 1
');
Thanks again !! :)