Parse error

I cannot find the reason what is causing an error when I run my PHP program. The error is :

Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\focusreport.php on line 185

I checked all the ‘{’ and ‘}’ and all seems to be correct. Also the ‘;’. Can you check and see what I am missing. The program is listed below:
[php]

<?php /** * focusreport.php * * Focusreport class file * * @version 1.0 2014-06-08 * @package Example */ /** Focusreport class * * @package Example */ class Focusreport { /** * Customer Number * @var string */ public $cust; /** * Vendor Number * @var string */ public $vend; /** * SumThree * * Three Month Summary Report * */ function SumThree() { echo "In SumThree function". '
'; $month = date('n'); $year = date('Y'); $lyear = ( date('Y') - 1 ); echo $month. '
'; echo $year. '
'; echo $lyear. '
'; $db_host = "localhost"; $db_username = "John"; $db_pass = "****"; $db_name = "awm"; $mysqli = new mysqli($db_host, $db_username, $db_pass, $db_name); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } echo "Database connected". '
'; if ($month == 1) { JanTY(); } elseif ($month == 2) { FebTY(); } elseif ($month == 3) { MarTY(); } elseif ($month == 4) { AprTY(); } elseif ($month == 5) { MayTY(); } elseif ($month == 6) { echo "June". '
'; JunTY(); } elseif ($month == 7) { echo "July". '
'; JulTY(); } elseif ($month == 8) { AugTY(); } elseif ($month == 9) { SepTY(); } elseif ($month == 10) { OctTY(); } elseif ($month == 11) { NovTY(); } elseif ($month == 12) { DecTY(); } } function JanTY() { } function FebTY() { } function MarTY() { } function AprTY() { } function MayTY() { } function JunTY() { //$JunTY = $mysqli->query("SELECT SUM(`CasesShip`) FROM sales2014 WHERE Cust_Code == $cust && // (Date >= 06/01/$year && <= 06/31/$year)); //$result = $JunTY; //echo $result; // $result = $mysqli->query("SELECT Name FROM City LIMIT 10")) // printf("Select returned %d rows.\n", $result->num_rows); } function JulTY() { $JulyTY = $mysqli->query("SELECT SUM(`CasesShip`) FROM sales2014 WHERE Cust_Code == $cust && (Date >= 07/01/$year && <= 07/31/$year)); $JulyTY->data_seek(0); while ($row = $JulyTY->fetch assoc()) { echo 'Total Cases: ' . $JulyTY->num_rows; } $JulyTY->free(); } function AugTY() { } function SepTY() { } function OctTY() { } function NovTY() { } function DecTY() { $result = 'The FocusList file shows as '.$this->cust.' and '.$this->vend; return $result; } } /** * DetailThree * * Three Month Detail Report * */ function DetailThree() { echo 'In DetailThree function'; $result = 'The Detail FocusList file shows as '.$this->cust.' and '.$this->vend; return $result; } /** * SumSix * * Six Month Summary Report * */ function SumSix() { echo 'In SumSix function'; $result = 'The Six Summary FocusList file shows as '.$this->cust.' and '.$this->vend; return $result; } /** * DetailSix * * Six Month Detail Report * */ function DetailSix() { echo 'In DetailSix function'; $result = 'The Six Detail FocusList file shows as '.$this->cust.' and '.$this->vend; return $result; } ?>

[/php]

OpzMaster: Encased the PHP code in the PHP code formatter for better viewing.

Hello,

After using the forum’s PHP code formatter, I found that you forgot the closing " in the query statement inside of the JulTY function. I don’t find anything else wrong with the code so I think that would take care of your error.

Also, in your SumThree function where you are using all those IF statements, I recommend using the SWITCH method to make it better:

[php]switch($month) {
case 1:
JanTY();
break;
case 2:
FebTY();
break;
case 3:
MarTY();
break;
case 4:
AprTY();
break;
case 5:
MayTY();
break;
case 6:
echo “June”. ‘
’;
JunTY();
break;
case 7:
echo “July”. ‘
’;
JulTY();
break;
case 8:
AugTY();
break;
case 9:
SepTY();
break;
case 10:
OctTY();
break;
case 11:
NovTY();
break;
case 12:
DecTY();
break;
}[/php]

Usually, the rule of thumb is if you are going to use more than 3 IF statements, it’s probably better to use a SWITCH statement. Let me know if this fixes your problem.

Cheers!

Thanks. Boy I did not see that at all. But I got a new error :frowning:

Parse error: syntax error, unexpected ‘assoc’ (T_STRING) in C:\xampp\htdocs\focusreport.php on line 132

I am not sure if I should use $row. I want to display the sum of total cases shipped.

[php]<?php
/**

  • focusreport.php
  • Focusreport class file
  • @version 1.0 2014-06-08
  • @package Example
    /
    /
    * Focusreport class
  • @package Example
    /
    class Focusreport
    {
    /
    *
  • Customer Number
  • @var string
    /
    public $cust;
    /
    *
  • Vendor Number
  • @var string
    */
    public $vend;

/**

  • SumThree
  • Three Month Summary Report

*/
function SumThree() {
echo “In SumThree function”. ‘
’;

$month = date(‘n’);
$year = date(‘Y’);
$lyear = ( date(‘Y’) - 1 );
echo $month. ‘
’;
echo $year. ‘
’;
echo $lyear. ‘
’;

$db_host = “localhost”;
$db_username = “John”;
$db_pass = “****”;
$db_name = “awm”;

$mysqli = new mysqli($db_host, $db_username, $db_pass, $db_name);
if ($mysqli->connect_errno) {
echo “Failed to connect to MySQL: (” . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}

echo “Database connected”. ‘
’;
switch($month) {
case 1:
JanTY();
break;
case 2:
FebTY();
break;
case 3:
MarTY();
break;
case 4:
AprTY();
break;
case 5:
MayTY();
break;
case 6:
echo “June”. ‘
’;
JunTY();
break;
case 7:
echo “July”. ‘
’;
JulTY();
break;
case 8:
AugTY();
break;
case 9:
SepTY();
break;
case 10:
OctTY();
break;
case 11:
NovTY();
break;
case 12:
DecTY();
break;
}

}

function JanTY() {

}

function FebTY() {

}

function MarTY() {

}

function AprTY() {

}

function MayTY() {

}

function JunTY() {
//$JunTY = $mysqli->query("SELECT SUM(CasesShip) FROM sales2014 WHERE Cust_Code == $cust &&
// (Date >= 06/01/$year && <= 06/31/$year));
//$result = $JunTY;
//echo $result;
// $result = $mysqli->query(“SELECT Name FROM City LIMIT 10”))
// printf(“Select returned %d rows.\n”, $result->num_rows);

}

function JulTY() {
$JulyTY = $mysqli->query(“SELECT SUM(CasesShip) FROM sales2014 WHERE Cust_Code == $cust &&
(Date >= 07/01/$year && <= 07/31/$year)”);
$JulyTY->data_seek(0);
while ($row = $JulyTY->fetch assoc()) {
echo "Total Cases: ". $JulyTY->num_rows;
}
$JulyTY->free();

}

function AugTY() {

}

function SepTY() {

}

function OctTY() {

}

function NovTY() {

}

function DecTY() {

$result = 'The FocusList file shows as ‘.$this->cust.’ and '.$this->vend;
return $result;
}
}

/**

  • DetailThree
  • Three Month Detail Report

*/
function DetailThree() {
echo ‘In DetailThree function’;
$result = 'The Detail FocusList file shows as ‘.$this->cust.’ and '.$this->vend;
return $result;
}

/**

  • SumSix
  • Six Month Summary Report

/
function SumSix() {
echo ‘In SumSix function’;
$result = 'The Six Summary FocusList file shows as ‘.$this->cust.’ and '.$this->vend;
return $result;
}
/
*

  • DetailSix
  • Six Month Detail Report

*/
function DetailSix() {
echo ‘In DetailSix function’;
$result = 'The Six Detail FocusList file shows as ‘.$this->cust.’ and '.$this->vend;
return $result;
}

?>[/php]

flyingvjohn,

In that line you have the function fetch assoc(). There is no space between fetch and assoc; the function is fetch_assoc() so the line should be:

[php]while ($row = $JulyTY->fetch_assoc())[/php]

Cheers!

Thanks to you for helping out :slight_smile: :slight_smile: :slight_smile: :slight_smile: :). I wish I found this site long time ago. I plan to read the tutorials on PHP on this site. I have alot to learn but I got to start somewhere. Thanks Again !!

Sponsor our Newsletter | Privacy Policy | Terms of Service