-
July 29th, 2002, 03:18 PM
#1
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
-
July 29th, 2002, 04:01 PM
#2
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
-
July 29th, 2002, 04:03 PM
#3
It's your last case statement. The correct syntax for a default case is just:
and not
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. */
-
July 29th, 2002, 04:04 PM
#4
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.
-
July 29th, 2002, 04:32 PM
#5
Hmmmm, Any ideas for tutorials or books?
-
July 29th, 2002, 05:38 PM
#6
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
-
July 29th, 2002, 05:51 PM
#7
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?
-
July 30th, 2002, 09:49 AM
#8
Banned
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!
-
July 30th, 2002, 03:01 PM
#9
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
-
Forum Rules
|
|