7 Replies - 2246 Views - Last Post: 16 September 2012 - 06:23 PM Rate Topic: -----

#1 BarNunBoi  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 232
  • Joined: 28-March 12

Parse error: syntax error, unexpected T_FOR

Posted 16 September 2012 - 05:21 PM

I am experiencing some problems with my code and I dont know what seems to be the problem. I have looked at my code for over an hour and cant seem to put my finger on this one....I am getting a Parse error: syntax error, unexpected T_FOR on line 42... I have tried adding ; at the end of line 40 but then I get a Parse error: syntax error, unexpected ';'..... here is my code
<?php
$saveTimeZone = date_default_timezone_get();
date_default_timezone_set('UTC'); // Php's date function uses this value!



require_once 'C:\wamp\www\PHPExcel\Classes\PHPExcel\IOFactory.php';
$objPHPExcel = PHPExcel_IOFactory::load("spreadsheet.xls");
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
    $worksheetTitle     = $worksheet->getTitle();
    $highestRow         = $worksheet->getHighestRow(); // e.g. 10
    $highestColumn      = $worksheet->getHighestColumn(); // e.g 'F'
    $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
    $nrColumns = ord($highestColumn) - 64;
    echo "<br>The Worksheet ".$worksheetTitle." has ";
    echo $nrColumns . ' columns (A-' . $highestColumn . ') ';
    echo ' and ' . $highestRow . ' rows.';
    echo '<br>Data: <table border="1"><tr>';
    for ($row = 1; $row <= $highestRow; ++ $row) {

        $rw1 = $worksheet->getCellByColumnAndRow(1,$row)->getValue();
                    $rw2 = $worksheet->getCellByColumnAndRow(2,$row)->getValue();
                    $rw3 = $worksheet->getCellByColumnAndRow(3,$row)->getValue();
                    $rw4 = $worksheet->getCellByColumnAndRow(4,$row)->getValue();
                    $rw5 = $worksheet->getCellByColumnAndRow(5,$row)->getValue();
                    $rw6 = $worksheet->getCellByColumnAndRow(6,$row)->getValue();
                    $rw7 = $worksheet->getCellByColumnAndRow(7,$row)->getValue();
                    $rw8 = $worksheet->getCellByColumnAndRow(8,$row)->getValue();
                    $rw9 = $worksheet->getCellByColumnAndRow(9,$row)->getValue();
                    $rw10 = $worksheet->getCellByColumnAndRow(10,$row)->getValue();
                    $rw11 = $worksheet->getCellByColumnAndRow(11,$row)->getValue();

        $slic = mysql_connect("xoxox", "xoxox", "xoxox");
                      if(!$slic) {
                    die('Could not connect' . mysql_error());;

                        }
        mysql_select_db("xoxoxo", $slic); 
        $dbc = ("INSERT INTO  Coverages( Name, Comments, Premium, Effective_Date, Expiration_Date, Broker_First_Name , Broker_Middle_Initial, Broker_Last_Name, Broker_Suffix, Broker_License_Number,  DateCreated))
                VALUES ('$rw1','$rw10','$rw2','$rw3', '$rw4', '$rw5','$rw6', '$rw7', '$rw8', '$rw9', '$rw11',)";
                
            for ($col = 0; $col < $highestColumnIndex; ++ $col) {
            $cell = $worksheet->getCellByColumnAndRow($col, $row);
            $val = $cell->getFormattedValue();
            $dataType = PHPExcel_Cell_DataType::dataTypeForValue($val);
            echo '<td>' . $val . '<br> </td>';
        }
         $conn = mysql_query($dbc, $conn) {
            if (!msql_query($dbc, $conn)) {
                die ('Error: ' . mysql_error());
                echo "recorded added"
            }
         }


    }
    echo '</table>';
}

date_default_timezone_set($saveTimeZone);
?>

This post has been edited by BarNunBoi: 16 September 2012 - 05:22 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Parse error: syntax error, unexpected T_FOR

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: Parse error: syntax error, unexpected T_FOR

Posted 16 September 2012 - 05:45 PM

The parenthesis on line 39 seem to be mismatched. Just before you open the string you open them, and then you have one extra inside the string at the end of that same line. Try removing them both.
Was This Post Helpful? 0
  • +
  • -

#3 BarNunBoi  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 232
  • Joined: 28-March 12

Re: Parse error: syntax error, unexpected T_FOR

Posted 16 September 2012 - 05:51 PM

I removed them as follows
  $dbc = "INSERT INTO  Coverages( Name, Comments, Premium, Effective_Date, Expiration_Date, Broker_First_Name , Broker_Middle_Initial, Broker_Last_Name, Broker_Suffix, Broker_License_Number,  DateCreated)
                VALUES ('$rw1','$rw10','$rw2','$rw3', '$rw4', '$rw5','$rw6', '$rw7', '$rw8', '$rw9', '$rw11',)"


now I get Parse error: syntax error, unexpected '{' on line 48

This post has been edited by BarNunBoi: 16 September 2012 - 05:55 PM

Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: Parse error: syntax error, unexpected T_FOR

Posted 16 September 2012 - 05:56 PM

Is the semicolon missing in the code as well?
Was This Post Helpful? 0
  • +
  • -

#5 BarNunBoi  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 232
  • Joined: 28-March 12

Re: Parse error: syntax error, unexpected T_FOR

Posted 16 September 2012 - 06:00 PM

no it is there....here is my code
<?php
$saveTimeZone = date_default_timezone_get();
date_default_timezone_set('UTC'); // Php's date function uses this value!



require_once 'C:\wamp\www\PHPExcel\Classes\PHPExcel\IOFactory.php';
$objPHPExcel = PHPExcel_IOFactory::load("spreadsheet.xls");
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
    $worksheetTitle     = $worksheet->getTitle();
    $highestRow         = $worksheet->getHighestRow(); // e.g. 10
    $highestColumn      = $worksheet->getHighestColumn(); // e.g 'F'
    $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
    $nrColumns = ord($highestColumn) - 64;
    echo "<br>The Worksheet ".$worksheetTitle." has ";
    echo $nrColumns . ' columns (A-' . $highestColumn . ') ';
    echo ' and ' . $highestRow . ' rows.';
    echo '<br>Data: <table border="1"><tr>';
    for ($row = 1; $row <= $highestRow; ++ $row) {

        $rw1 = $worksheet->getCellByColumnAndRow(1,$row)->getValue();
                    $rw2 = $worksheet->getCellByColumnAndRow(2,$row)->getValue();
                    $rw3 = $worksheet->getCellByColumnAndRow(3,$row)->getValue();
                    $rw4 = $worksheet->getCellByColumnAndRow(4,$row)->getValue();
                    $rw5 = $worksheet->getCellByColumnAndRow(5,$row)->getValue();
                    $rw6 = $worksheet->getCellByColumnAndRow(6,$row)->getValue();
                    $rw7 = $worksheet->getCellByColumnAndRow(7,$row)->getValue();
                    $rw8 = $worksheet->getCellByColumnAndRow(8,$row)->getValue();
                    $rw9 = $worksheet->getCellByColumnAndRow(9,$row)->getValue();
                    $rw10 = $worksheet->getCellByColumnAndRow(10,$row)->getValue();
                    $rw11 = $worksheet->getCellByColumnAndRow(11,$row)->getValue();

        $slic = mysql_connect("xoxox", "xoxoxo", "xoxox");
                      if(!$slic) {
                    die('Could not connect' . mysql_error());;

                        }
        mysql_select_db("xoxoxo", $slic); 
        $dbc = "INSERT INTO  Coverages( Name, Comments, Premium, Effective_Date, Expiration_Date, Broker_First_Name , Broker_Middle_Initial, Broker_Last_Name, Broker_Suffix, Broker_License_Number,  DateCreated)
                VALUES ('$rw1','$rw10','$rw2','$rw3', '$rw4', '$rw5','$rw6', '$rw7', '$rw8', '$rw9', '$rw11',)";

            for ($col = 0; $col < $highestColumnIndex; ++ $col) {
            $cell = $worksheet->getCellByColumnAndRow($col, $row);
            $val = $cell->getFormattedValue();
            $dataType = PHPExcel_Cell_DataType::dataTypeForValue($val);
            echo '<td>' . $val . '<br> </td>';
        }
         $conn = mysql_query($dbc, $conn) {
            if (!msql_query($dbc, $conn)) {
                die ('Error: ' . mysql_error());
                echo "recorded added"
            }
         }


    }
    echo '</table>';
}

date_default_timezone_set($saveTimeZone);
?>

This post has been edited by BarNunBoi: 16 September 2012 - 06:03 PM

Was This Post Helpful? 0
  • +
  • -

#6 BarNunBoi  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 232
  • Joined: 28-March 12

Re: Parse error: syntax error, unexpected T_FOR

Posted 16 September 2012 - 06:12 PM

I think I got it hammered out....I am getting the Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Access denied for user error.....which I think my user name and password is wrong
Was This Post Helpful? 0
  • +
  • -

#7 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: Parse error: syntax error, unexpected T_FOR

Posted 16 September 2012 - 06:18 PM

Yep you wouldn't be getting MySQL errors if there were still PHP syntax errors :)

By the way, there is a syntax error in your INSERT query. You've got an extra comma after all your values.
Was This Post Helpful? 0
  • +
  • -

#8 BarNunBoi  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 232
  • Joined: 28-March 12

Re: Parse error: syntax error, unexpected T_FOR

Posted 16 September 2012 - 06:23 PM

Thanks!! My noobie eyes missed that!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1