Link to home
Start Free TrialLog in
Avatar of siamesefish
siamesefish

asked on

URGENT: PHP QUERY

I asked a PHP related question and get a great reply the other day from someone here.
(Thanks again : )

I've tested the codes on my own server and it worked perfectly.
Here is the code. (Reads data from text file, info.txt and displays the text on a page)

-------------------------------------------------------
<?php
//
// This is looking for 1 parameter and it supplies the
// name of a file to display on the site.  
//

 $txtfile = $_GET['Id'] . '.txt';
     
if ($txtfile <> "null") {
     $Open = fopen ($txtfile, "r");
     if ($Open) {
          $data = file ($txtfile);
          for ($n = 0; $n < count($data); $n++) {
               $GetLine = explode("\t",$data[$n]);
               print ("$GetLine[0]<br>");
          }

          while ($n++ < 15) {
               print ("<br>");
          }
          fclose ($Open);
     } else {
     print ("Error opening event file.");
     }
}

?>
-------------------------------------------------------

The file is called as such: http://www.beyondresearch.sg/notice_board.php?Id=info

Problem is with this new domain host is that somehow thier PHP engine cannot seem to read the codes and process them properly and I get this error message:

Error opening event file.

So im back to square one again. I have notified this domain host and they tell me to check on the php version requirement and whether will this php script works on a Windows server running php.

Would any kind fellow here know what kind of PHP requirements the server would need and if my code is suitable? I am not really a programmer and have no idea where to find the answer to this but here. Any help would be much appreciated. Thank you all.

EJQ
ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of siamesefish
siamesefish

ASKER

Thanks rockiroads, where should i put that part of the code?
u can put it after you check for null and before u do fopen

if ($txtfile <> "null") {
     if file_exists($txtfile)) {
         $Open = fopen ($txtfile, "r");
         if ($Open) {
              $data = file ($txtfile);
              for ($n = 0; $n < count($data); $n++) {
                   $GetLine = explode("\t",$data[$n]);
                   Print ("$GetLine[0]<br>");
              }
   
              while ($n++ < 15) {
                   Print ("<br>");
              }
              fclose ($Open);
         } else {
            Print ("Error opening event file.");
         }
    } else {
        Print ("File not found");
    }
}



suggest u print the name of the txtfile in your error messages
I think this will work

print ("File $txtfile not found");


is_readable returns TRUE if the file or directory specified by filename exists and is readable.
file_exists returns TRUE if the file or directory specified by filename exists; FALSE otherwise

so I guess is_readable is also a valid option
try both (change file_exists to is_readable), see what happens
I've tried all that.
Now instead of the the error message displaying.
The page comes out blank. : ( What should i do?
does the textfile actuall contain anything? add some diagnostics

e.g.

if ($Open) {
    Print "HELLO - START READING FILE<br>");
              $data = file ($txtfile);
              for ($n = 0; $n < count($data); $n++) {
                   $GetLine = explode("\t",$data[$n]);
                   Print ("READLINE HERE -- $GetLine[0]<br>");
              }
   
              while ($n++ < 15) {
                   Print ("<br>");
              }
    Print "BYE - DONE READING FILE<br>");
              fclose ($Open);
oops type in print statement

did u spot it?

if ($Open) {
              Print ("HELLO - START READING FILE<br>");
              $data = file ($txtfile);
              for ($n = 0; $n < count($data); $n++) {
                   $GetLine = explode("\t",$data[$n]);
                   Print ("READLINE HERE -- $GetLine[0]<br>");
              }
   
              while ($n++ < 15) {
                   Print ("<br>");
              }
              Print ("BYE - DONE READING FILE<br>");
              fclose ($Open);


missing open bracket in print statement doh!
hahaha lemme try! brb
the text file contains quiet a bit off stuff
ive tried all options but it just wont display.
i must be some server problem.
if u not getting anything at all, I wonder if there is a problem with the PHP?

At least before u was getting a page to appear with error message
You can prove if this is the case, if u revert back to original code that u had working

If that is the case then do you have any tools which compiles PHP? It will help identify any possible errors with the new code

I will contact the host. See what their input on the case is.
If i dont get a solution in 2 days or so I'll give you the full 500 points.
Either way you have been great. Superb. Thanks rockiroads.
no probs. I would like u to revert back to what u had though, so at least the page is coming up

perhaps is_readable or file_exists is not supported, hence the use of the compiler
You would have to compile on the host, dont know if that would be possible

Its more important to get u going. Have u thought of posting a quick 20ptr question on the PHP section? Create a question with a link to this question. Hopefully someone may be able to offer more help.