Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 8th, 2003, 06:53 PM
FromundaCheese's Avatar
FromundaCheese FromundaCheese is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Saskatchewan
Posts: 24 FromundaCheese User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question how come ...?

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.

Reply With Quote
  #2  
Old March 8th, 2003, 08:42 PM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,344 jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 Days 6 h 26 m 32 sec
Reputation Power: 787
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.

Reply With Quote
  #3  
Old March 9th, 2003, 08:48 PM
FromundaCheese's Avatar
FromundaCheese FromundaCheese is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Saskatchewan
Posts: 24 FromundaCheese User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up

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.

Reply With Quote
  #4  
Old March 9th, 2003, 09:43 PM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,344 jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 Days 6 h 26 m 32 sec
Reputation Power: 787
You should keep register_globals off IMO. Using the superglobals $_POST/$_GET/etc makes your code easier to read and it's more secure.

Reply With Quote
  #5  
Old March 9th, 2003, 11:49 PM
FromundaCheese's Avatar
FromundaCheese FromundaCheese is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Saskatchewan
Posts: 24 FromundaCheese User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.. ?

Reply With Quote
  #6  
Old March 10th, 2003, 12:33 AM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,344 jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level)jharnois User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 Days 6 h 26 m 32 sec
Reputation Power: 787
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:
 define('COMPANY''foobar');

echo 
COMPANY// prints foobar 
You can use $_GET[COMPANY], but what it looks for then is domain.com?foobar=this, so echo $_GET[COMPANY] would print "this" for the above URL.

Reply With Quote
  #7  
Old March 10th, 2003, 12:39 AM
FromundaCheese's Avatar
FromundaCheese FromundaCheese is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Saskatchewan
Posts: 24 FromundaCheese User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > how come ...?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway