0

I am using http://www.000webhost.com/ as a web server. My code works perfectly on the localhost but online I am getting this error

Parse error: syntax error, unexpected T_STRING in /home/a1582910/public_html/setcore/create.php on line 1

and I cannot fix it because I do not understand the problem because as you know the code is in one line all of it is in line one :D so

after searching i found that the names of the variables is case sensitive so i made it all in small letters and i still having the same error.

Can any one help?

I am using WAMPSERVER (32 BITS & PHP 5.4) create.php contains the following

<html>
<head>
 </head>
 <body>
 <?php
 class invoice {

 function addninvoice ($i) {

 require_once 'PHPExcel_1.7.9_doc/Classes/PHPExcel.php';
 /** PHPExcel */require_once 'PHPExcel_1.7.9_doc/Classes/PHPExcel/IOFactory.php';

  $excel2 = PHPExcel_IOFactory::createReader('Excel2007');
  $excel2 = $excel2->load('try.xlsx');

   $excel2->setActiveSheetIndex(0);
   echo"".$excel2->getActiveSheet()->getHighestRow()."";
   $psheet = $excel2->getActiveSheet();

   $excel22 = PHPExcel_IOFactory::createReader('Excel2007');
    $excel22 = $excel22->load('try.xlsx');
   $psheet->setTitle($i);
   $psheet->setCellValue('G7', $i);


   $excel22->addSheet($psheet);
  $obr = PHPExcel_IOFactory::createWriter($excel22, 'Excel2007');
  $obr->save('try1.xlsx');                           

  $excel222 = PHPExcel_IOFactory::createReader('Excel2007');
  $excel222 = $excel222->load('try1.xlsx');

  $o = PHPExcel_IOFactory::createWriter($excel222, 'Excel2007');
  $o->save('try.xlsx');

                    }       

                    }   

 $p=new invoice;
 $in = $_GET['in'];

  require_once 'PHPExcel_1.7.9_doc/Classes/PHPExcel/IOFactory.php';
  $excel2 = PHPExcel_IOFactory::createReader('Excel2007');
  $sna = $excel2->listWorksheetNames("try.xlsx");
  $df=0;
  foreach($sna as $id => $name ){ 

  if($name==$in){ $df++; }

        }

   if($df != 0){

   echo"this invoice already exist
   you can not create two invoices with the same name
   if you want to edit it just click on it from the left menu in the home page" ;

   }else{

   $p->addninvoice($in);
   ?><meta http-equiv="Refresh" content="0; url=fa.php"><?php

    }

   ?>
   </body>
   </html>

fa.php

  <html>
  <head>
  <script>
  function validateForm()
  {
  var x=document.forms["numrownamche"]["in"].value;
  if (x==null || x=="")
    {
    alert("Invoice Name Must Be Filled Out");
    return false;
    }
  }
  </script>
  </head>
  <body bgcolor="silver">
  <img src="image/Logo.gif" alt="Setcore" width="199">
  <b>create new invoice</b>



  <form name="numrownamche" action="create.php" onsubmit="return validateForm()"                                method="get">
   <br/><small>invoice number:</small> <input type="text" name="in">
   <input type="submit" value="Create">
     </form>




   <?php
   require_once 'PHPExcel_1.7.9_doc/Classes/PHPExcel/IOFactory.php';
   $excel2 = PHPExcel_IOFactory::createReader('Excel2007');
   $sna = $excel2->listWorksheetNames("try.xlsx");
   foreach($sna as $id => $name ){ 


    ?>

   <a href="fb.php?shtid=<?php echo $id; ?>" target="fb"><?php echo "".$name."<br/>";?>                        </a>




    <?php

            }

        ?>

        </body>
      </html>

3 Answers3

0

Aren't you missing something like a semicolon ;

If you have any database connect function before this files, check that as well.

Amit Malakar
  • 618
  • 1
  • 5
  • 10
  • i do not have any database. but i am editing an excel file by adding some excel sheets and editing in it – Haitham El Amashety Aug 09 '13 at 04:39
  • i just tried what Curtis Mattoon said it works now in a case but in the other case i get this Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 103 bytes) in /home/a1582910/public_html/setcore/PHPExcel_1.7.9_doc/Classes/PHPExcel/Worksheet‌​.php on line 1136 – Haitham El Amashety Aug 09 '13 at 04:52
0

It might be because of PHP version. 000webhost has php 5.2.17 which might not be able to run your code.

http://server12.000webhost.com/phpinfo.php

Ahmad Azizov
  • 166
  • 2
  • 12
  • but the code works fine in the other bags.is it possible to work in some bages and not in the other ? and haw can i now what version of php i am working with ? and if i now haw can i know the different between it and version 5.2.17 ? – Haitham El Amashety Aug 09 '13 at 04:38
  • http://php.net/ChangeLog-5.php You can also check the migration pages (e.g., http://www.php.net/manual/en/migration54.deprecated.php) or see the "What's changed" pages (http://php.net/manual/en/migration54.changes.php) and/or new features (http://php.net/manual/en/migration54.new-features.php) – Curtis Mattoon Aug 09 '13 at 04:38
  • i just tried what Curtis Mattoon said it works now in a case but in the other case i get this Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 103 bytes) in /home/a1582910/public_html/setcore/PHPExcel_1.7.9_doc/Classes/PHPExcel/Worksheet‌​‌​.php on line 1136 – Haitham El Amashety Aug 09 '13 at 04:53
0

Try adding an empty

<?php
?>

to the beginning of your file, before the <html> tag. I'm not sure why, but I've noticed that it fixes problems with mixed PHP/HTML.

Additionally, sometimes a null byte or other invisible char creeps in before the start tag, depending on file encoding/editor used/copy & paste, etc. Try deleting the entire first line and re-typing it and see if that fixes your problem.

Curtis Mattoon
  • 4,642
  • 2
  • 27
  • 34
  • are you kidding me man you are a wizard not a brogrammer :D i just did it it works now in one case but in the other one i get this error Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 103 bytes) in /home/a1582910/public_html/setcore/PHPExcel_1.7.9_doc/Classes/PHPExcel/Worksheet.php on line 1136 – Haitham El Amashety Aug 09 '13 at 04:50
  • Try increasing your allocated memory through php.ini or with `ini_set` (http://davidwalsh.name/increase-php-memory-limit-ini_set), if your host allows it. – Curtis Mattoon Aug 09 '13 at 04:55
  • ini_set('memory_limit','16M'); what do you think 16m will be good ? – Haitham El Amashety Aug 09 '13 at 05:00
  • It depends on the size of your spreadsheet and what's using up the memory. You currently have 64M of memory, so I'd try going to 128, then 256, etc. If it's not solved after a decent amount of memory has been allocated, it's probably a code issue. Not that libraries like that are infallible, but if there's an issue with memory being exceeded, I'd check the data you're passing into it (check loops espicially). PHPExcel has some known memory issues, you might check out: http://stackoverflow.com/questions/4817651/phpexcel-runs-out-of-256-512-and-also-1024mb-of-ram – Curtis Mattoon Aug 09 '13 at 05:04
  • i made it ini_set("memory_limit","256M"); and i wrote it in the index.php and in creat.php now it workes well can i ask you another question do rely trust your answers . now after creat.php as you can see i want it to go to fa.php which is a frame in my home bage this frame retrive all the crated work sheets name and print it the problem is that i can`t find the sheet now i have to refresh to view the work sheet that i just created . any ideas ? is the something wrong in this line is it content="0 the problem ? – Haitham El Amashety Aug 09 '13 at 05:11
  • See if `header('Location: fa.php'); die();` works. – Curtis Mattoon Aug 09 '13 at 05:13
  • do you meen replace with header('Location: fa.php'); die(); – Haitham El Amashety Aug 09 '13 at 05:16
  • 1
    Yeah. Inside your ELSE block. – Curtis Mattoon Aug 09 '13 at 05:21
  • just did it and it is not working even the is not working too now i have to wight 55 seconds to view the new work sheet listed – Haitham El Amashety Aug 09 '13 at 05:32
  • you can see fa.php that displayes the sheet names now – Haitham El Amashety Aug 09 '13 at 05:45