PHP Help...
Results 1 to 9 of 9

Thread: PHP Help...

  1. #1
    Banned
    Join Date
    Oct 2001
    Posts
    1,462

    PHP Help...

    Ok, I know im probably annoying many people witht hese PHP and MySQL posts... So in addition to helping me out on this can anyone point me to a good PHP tutorial for beginners

    And now my problem.... It is the same problem... But now I am using case statements instead of if..... When I try to set the default page using case default It gives me a parse error....
    Code:
    Parse error: parse error, unexpected T_DEFAULT in D:\Apache\htdocs\book.php on line 20
    This is my code:
    PHP Code:
    <?php
    $book 
    $_GET["book"];   // this reads the variable "page" in the array $_GET
    switch ($book) {
       case 
    1:
          
    header"Content-Type: application/pdf" );
          
    readfile"/books/C#_Book.pdf" );
          break;
       case 
    2:
          
    header"Content-Type: application/pdf" );
          
    readfile"perl.pdf" );
          break;
       case 
    3:
          
    header"Content-Type: application/pdf" );
          
    readfile"perl.pdf" );
          break;
       case 
    4:
          
    header"Content-Type: application/pdf" );
          
    readfile"perl.pdf" );
          break;
        case default:
          
    header"Content-Type: text/html" );
          
    readfile"books.html" );
    }
    ?>
    PS: When I try to do a ?book=1 it tells me this:
    Code:
    
    Warning:  readfile("/books/C#_Book.pdf") - No such file or directory in D:\Apache\htdocs\book.php on line 6
    Any idea or a better way of getting this done

  2. #2
    AntiOnline Senior Member souleman's Avatar
    Join Date
    Oct 2001
    Location
    Flint, MI
    Posts
    2,884
    case default:
    I believe that the default doesn't have the word case in front of it.... should be:
    PHP Code:
       case 4:
          
    header"Content-Type: application/pdf" );
          
    readfile"perl.pdf" );
          break;
       default:
          
    header"Content-Type: text/html" );
          
    readfile"books.html" );

    http://www.phpworld.com/manual/contr...es.switch.html

    No idea about your other problem. I really don't know php.
    \"Ignorance is bliss....
    but only for your enemy\"
    -- souleman

  3. #3
    Senior Member roswell1329's Avatar
    Join Date
    Jan 2002
    Posts
    670
    It's your last case statement. The correct syntax for a default case is just:

    PHP Code:
    default: 
    and not

    PHP Code:
    case default: 
    Try that first, and see if that takes care of your first error.

    http://www.php.net/manual/en/control...res.switch.php


    As for your second error, at first glance it looks like you've got a path mixed up. Is there a "books" directory at your html root, or is it down a few paths? Also, I know that PHP can do some spiffy things with PDF files, but I'm not if it can read PDF files with a straight "readfile". PDF's act more like images than they do documents. If you just want to open the PDF for the user to read, it might be easier to just redirect to that file.
    /* You are not expected to understand this. */

  4. #4
    Hi mom!
    Join Date
    Aug 2001
    Posts
    1,103
    For the second error: try using a filename without the #-character in it...
    I wish to express my gratitude to the people of Italy. Thank you for inventing pizza.

  5. #5
    Banned
    Join Date
    Oct 2001
    Posts
    1,462
    Hmmmm, Any ideas for tutorials or books?

  6. #6
    AntiOnline Senior Member souleman's Avatar
    Join Date
    Oct 2001
    Location
    Flint, MI
    Posts
    2,884
    Your either getting gready or lazy in your old age ac1dsp3ctrum.....

    http://perl.about.com/cs/beginningphp/ A bunch of beginning php tutorials...

    http://directory.google.com/Top/Comp...PHP/Tutorials/ A lot more (and more advanced) tutorials....
    \"Ignorance is bliss....
    but only for your enemy\"
    -- souleman

  7. #7
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,255
    Originally posted here by Guus
    For the second error: try using a filename without the #-character in it...
    Alternately, you can keep it, but you have to escape the hash mark.
    Chris Shepherd
    The Nelson-Shepherd cutoff: The point at which you realise someone is an idiot while trying to help them.
    \"Well as far as the spelling, I speak fluently both your native languages. Do you even can try spell mine ?\" -- Failed Insult
    Is your whole family retarded, or did they just catch it from you?

  8. #8
    Banned
    Join Date
    Nov 2001
    Posts
    43
    the best resource you could possibly find on php is the manual at php.net. It's great for reference of for finding functions. Another nice thing about it is that users contribute code/tips on each topic...so chek it out now!

  9. #9
    Hi mom!
    Join Date
    Aug 2001
    Posts
    1,103
    I agree with hurt-conveyor here. The php.net documentation is valuable...
    I wish to express my gratitude to the people of Italy. Thank you for inventing pizza.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •