p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Need some help! Please!!


Message #1 by rbanse@c... on Fri, 26 Apr 2002 04:29:09
Ok, this is very simple but is stumping me big time. I'm doing the 
tutorial, Beginning PHP, Chapter 3, pg 80.  After I create my html and 
php files, I run the html page.  Type in "A favorite website", and then 
submit the query.  But on the following php page, it doesn't show my 
input that I entered.  It just shows  "Your favorite website is"  and 
then there is no data following that.  I'm typing in the code EXACTLY as 
it shows in the book and it still doesn't work??? Any ideas what I can 
look for??  I know this is a very simple example, but it's not working 
for some reason! Help!  Thanks alot.  Ryan

P.S.  I'm almost certain my php engine is working fine, because when I 
run a seperate script  phpinfo()  it displays my configuration fine.  
Version PHP 4.1.2
Message #2 by "Josh" <jeb_braun@i...> on Fri, 26 Apr 2002 06:58:03
COuld you post your code. Because I have had problems before when I was 
sure the code was right, I'd read it over and over but didn't notice the 
porblem. Then would get someone else to look it over and spot it. So yea 
you should post the code.

Josh
Message #3 by rbanse@c... on Fri, 26 Apr 2002 13:04:22
Here's the code: 
HTML File:

<HTML>
<HEAD></HEAD>
<BODY>
<FORM METHOD=POST ACTION="textarea.php">
What are your favorite web sites?
<TEXTAREA NAME="WebSites" COLS="50" ROWS="5">
http://
http://
http://
http://
</TEXTAREA>
<BR>
<BR>
<BR>
<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>


PHP FILE:
<HTML>
<HEAD></HEAD>
<BODY>
Your favorite web sites are:
<?php
echo $WebSites;
?>
</BODY>
</HTML>


> COuld you post your code. Because I have had problems before when I was 
s> ure the code was right, I'd read it over and over but didn't notice 
the 
p> orblem. Then would get someone else to look it over and spot it. So 
yea 
y> ou should post the code.

> Josh
Message #4 by =?iso-8859-1?q?Andrew=20Walker?= <catbert303@y...> on Fri, 26 Apr 2002 14:27:57 +0100 (BST)
You could try looking through the page generated when
you run your phpinfo script and check whether
register_globals is set to on or off, if it is off try
editting your PHP file to read

$WebSites = $HTTP_POST_VARS['WebSites'];
echo $WebSites;

Andy

--- rbanse@c... wrote: > Ok, this is very
simple but is stumping me big time.
> I'm doing the 
> tutorial, Beginning PHP, Chapter 3, pg 80.  After I
> create my html and 
> php files, I run the html page.  Type in "A favorite
> website", and then 
> submit the query.  But on the following php page, it
> doesn't show my 
> input that I entered.  It just shows  "Your favorite
> website is"  and 
> then there is no data following that.  I'm typing in
> the code EXACTLY as 
> it shows in the book and it still doesn't work???
> Any ideas what I can 
> look for??  I know this is a very simple example,
> but it's not working 
> for some reason! Help!  Thanks alot.  Ryan
> 
> P.S.  I'm almost certain my php engine is working
> fine, because when I 
> run a seperate script  phpinfo()  it displays my
> configuration fine.  
> Version PHP 4.1.2

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com
Message #5 by rbanse@c... on Mon, 29 Apr 2002 19:25:05
Thanks that helped! I turned on Register_Globals in the php.ini file and 
all is well. Thanks again.  RB


> You could try looking through the page generated when
you run your phpinfo script and check whether
register_globals is set to on or off, if it is off try
editting your PHP file to read

$WebSites = $HTTP_POST_VARS['WebSites'];
echo $WebSites;

Andy

--- rbanse@c... wrote: > Ok, this is very
simple but is stumping me big time.
> I'm doing the 
> tutorial, Beginning PHP, Chapter 3, pg 80.  After I
> create my html and 
> php files, I run the html page.  Type in "A favorite
> website", and then 
> submit the query.  But on the following php page, it
> doesn't show my 
> input that I entered.  It just shows  "Your favorite
> website is"  and 
> then there is no data following that.  I'm typing in
> the code EXACTLY as 
> it shows in the book and it still doesn't work???
> Any ideas what I can 
> look for??  I know this is a very simple example,
> but it's not working 
> for some reason! Help!  Thanks alot.  Ryan
> 
> P.S.  I'm almost certain my php engine is working
> fine, because when I 
> run a seperate script  phpinfo()  it displays my
> configuration fine.  
> Version PHP 4.1.2

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com
Message #6 by "Dan Ostrowski" <dan@t...> on Mon, 29 Apr 2002 19:36:14
on a practical note, it is a better idea to turn globals OFF, as they will 
be shut off by default in all subsequent PHP releases. Security issues.

Get used to running through and using $HTTP_POST_VARS, or if you have the 
more recent version, $_POST.

I used to be afraid/annoyed by those arrays, and avoid using them, 
trusting globals to be turned on.  However, that is not very smart 
practice, especially for the continued use of applications you write.

What I have found, though, is that it is MUCH MORE convenient to boot!  
When you start writing larger applications, you can tailor make 
functions/subroutines that go through and accept and store user input 
using the "$HTTP_POST_VARS" array or whatever.  Saves a lot of time for 
you in the long run.

Example:

instead of manually typing in the PHP code to receive values, you can do 
something like this: (this is just pseudo-code)

while (list($index, $contents) = each($HTTP_POST_VARS)) {
     /* do a function that uses other functions to determine what to do 
with data */
    
     mySortingFunction($index, $contents);
}


this sort of code (when elaborated upon) could be expanded for use with 
several forms, and even used in other projects!  That's actually what I am 
working on right now, is a comprehensive application to do generic form 
handling.. using the HTTP_POST_VARS array, I will be able to use this 
application for almost every project I will ever do with PHP and MySQL!



bottom line, I would turn globals back on and get used to using the VARS 
arrays.

cheers,
dan
Message #7 by "Dan Ostrowski" <dan@t...> on Mon, 29 Apr 2002 19:38:19
DOH! typo:

> bottom line, I would turn globals back on and get used to using the VARS 
arrays.

i meant, turn OFF globals.


regards,
dan
Message #8 by rbanse@c... on Tue, 30 Apr 2002 04:02:55
Ok, will do that, read some info on the register_globals.... I kinda got 
lost though in your example, so for the following:

----------------------------
echo $WebSites;
?>
</BODY>
</HTML>
----------------------------

I would change it to for every variable!!???!!??:

----------------------------
$WebSites = $HTTP_POST_VARS['WebSites'];
echo $WebSites;


Thanks. Ryan



> DOH! typo:

> > bottom line, I would turn globals back on and get used to using the 
VARS 
a> rrays.

> i meant, turn OFF globals.

> 
r> egards,
d> an

  Return to Index