|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Hey everyone, I am sort of new to PHP programming.. I got the book titled "Professional PHP Programming" by Jesus Castagnetto, Harish Rawat, and 3 others.. It is published by WROX press. As I'm going through the first few chapters I realize that when I try to do a basic echo statement with a variable in it which should be taken from the form above it, it will not do anything! Here is the code I am trying to use that will not work:
<HTML> <FORM> Please type your name here:<BR> <INPUT TYPE=TEXT NAME=username><BR><BR> <INPUT TYPE=SUBMIT VALUE="Submit"> </FORM> <BR><BR> You typed: <?php echo ($username); ?> </HTML> Is there a reason that it will not ever show the PHP part of this page? It works when I use a two page version, using the POST statement. But every time I try to insert a variable like above, it leaves an empty space unless I define the variable like : $username="Fromunda". Any reason for this? I find that it is when I have a variable defined in the URL such as when it tries to load "Http://fromundacheese.no-ip.org/test.php?username=whateveristyped" that the problem occurs. It doesn't seem to use these variables... SOMEONE HELP! PLEASE! Is it possibly my server? I am running the Apache webserver on windows 2000 and haven't had any problems with it as of yet. I did notice that I am using PHP4 (the latest version on php.net, whatever the decimal places are) and in the book I am following they use PHP3. Any help would be greatly appreciated! Oh, and when I hit the submit button the URL does show the correct url "Http://fromundacheese.no-ip.org/PHP/test.php?username=whateveristyped" but the page stops after "You typed:" Last edited by FromundaCheese : March 8th, 2003 at 07:13 PM. |
|
#2
|
||||
|
||||
|
How old is that book?
Your problem is probably related to the register_globals setting, which when that book was made was probably on by default and now the defaul is off. register_globals took variables from POSTed forms and variables that are passed in the URL's query string and automatically made them variables. What that means is that with a URL like domain.com/page.php?username=foobar, that the variable $username was automatically registered as a variable with the value "foobar" in the page.php script. Take a look at $_GET and $_POST in the section on variables in the PHP manual. Your script should say echo $_GET['username'] instead of just echo $username. Why it works when posting to a different page I don't know. Your page does have a .php extension right? As for your book -- sounds be a little outdated and while it may help you understand some concepts, I think you better read the manual along with it. [edit]Oh, and your thread subject isn't acceptable for this community. Please read the Stickys at the top of the PHP forum before posting another thread. There's just good information there too![/edit] Last edited by jharnois : March 8th, 2003 at 08:46 PM. |
|
#3
|
||||
|
||||
|
Thanks, I'll check that out. Sorry about not reading where to post this stuff.. I was/am just kind of in a hurry to get started because I understand the programming language so far, its just that it wouldn't work when i tried.. hehh. So, this register globals, I could just set it to ON and it should work? or is there a reason that its default is off? [edit]Don't worry about it, I figured it out. :P that was really easy. lol. Thanks though, you pointed me in the right direction.[/edit]
![]() Last edited by FromundaCheese : March 9th, 2003 at 09:21 PM. |
|
#4
|
||||
|
||||
|
You should keep register_globals off IMO. Using the superglobals $_POST/$_GET/etc makes your code easier to read and it's more secure.
|
|
#5
|
||||
|
||||
|
Okay, thanks. I have been progressing through this book now, just changing the echo ($variable) statements to echo $_GET or $_POST as needed. I just ran into a spot where Im not sure what to do though. It wants a defined variable in an echo statement.. $_GET[COMPANY] does not work, i did the
<?php define ("COMPANY", "Blah blah"); ?> statement, and I can't figure out how to make "Blah blah" show up on screen when I use <H1><?php echo $_GET[COMPANY]; ?> blah</H1> Am I just dumb or is there something I don't know yet.. ? |
|
#6
|
||||
|
||||
|
When you use define(), you're defining a constant. Constants don't need the dollar sign nor do they need $_GET/$_POST or anything else. When you define a constant, you use just that.
PHP Code:
|
|
#7
|
||||
|
||||
|
OOOOkay! thanks a million! I'm doin great with PHP so far. Probably because I took a Visual Basic course last semester and got 90%. I understand programming, its just these little things that get me. heheh
|
![]() |
| Viewing: Dev Shed Forums > Other > Beginner Programming > how come ...? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|