Newbie Question - PHP variable not working

This is a discussion on Newbie Question - PHP variable not working within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hello, I'm just starting out using PHP with DWMX2004, and have hit a stumbling block whilst trying to run ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-11-2004
JD
 
Posts: n/a
Default Newbie Question - PHP variable not working

Hello,

I'm just starting out using PHP with DWMX2004, and have hit a stumbling
block whilst trying to run a very simple excercise. It's probably something
quite silly that I'm missing, but having read tutorials etc again and again,
I can't see what it is. I'm hoping someone might be able direct me to what
is wrong.

Basically I have a form which asks the user to select one of two possible
states for a variable, mypet. When the type of pet is selected, an new page
opens, which is supposed to show what type of pet was selected, ...but it
doesn't.

When the second page opens, the line:-
http://localhost/newland/animal_home_page.php?mypet=Cat does appear in the
URL bar, which looks to me like the variable is getting assigned. But only a
blank space appears in the page text where the animal name is supposed to
be.

I've included a copy of the source below. I hope someone may be able to see
where I'm going wrong.

I have Apache 2.0.47 & PHP 4.3.3 installed on a Windows XP Pro machine
configured as a local host.


**** First Page ****

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<h1>Are You a Cat Person or a Dog Person?</h1>
<p>I am a <a href="animal_home_page.php?mypet=Cat">Cat</a> person</p>
<p>I am a <a href="animal_home_page.php?mypet=Dog">Dog</a> person </p>
</body>
</html>


******************
****Second Page****

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<h1>The <?php echo $_GET['mypet']; ?> Person Home Page?</h1>
<p>I am a <?php echo $_GET['mypet']; ?> person. </p>
</body>
</html>

**********************

Many thank

J


Reply With Quote
  #2 (permalink)  
Old 06-11-2004
Molle
 
Posts: n/a
Default Re: Newbie Question - PHP variable not working

Hello J,
This is the right syntax:

<h1>The <?php print $mypet; ?> Person Home Page?</h1>

Goodluck,

Molle


"JD" <nospam@toomuchspam.com> schreef in bericht
news:J9kyc.79605$wd7.15360@front-1.news.blueyonder.co.uk...
> Hello,
>
> I'm just starting out using PHP with DWMX2004, and have hit a stumbling
> block whilst trying to run a very simple excercise. It's probably

something
> quite silly that I'm missing, but having read tutorials etc again and

again,
> I can't see what it is. I'm hoping someone might be able direct me to what
> is wrong.
>
> Basically I have a form which asks the user to select one of two possible
> states for a variable, mypet. When the type of pet is selected, an new

page
> opens, which is supposed to show what type of pet was selected, ...but it
> doesn't.
>
> When the second page opens, the line:-
> http://localhost/newland/animal_home_page.php?mypet=Cat does appear in the
> URL bar, which looks to me like the variable is getting assigned. But only

a
> blank space appears in the page text where the animal name is supposed to
> be.
>
> I've included a copy of the source below. I hope someone may be able to

see
> where I'm going wrong.
>
> I have Apache 2.0.47 & PHP 4.3.3 installed on a Windows XP Pro machine
> configured as a local host.
>
>
> **** First Page ****
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
> </head>
>
> <body>
> <h1>Are You a Cat Person or a Dog Person?</h1>
> <p>I am a <a href="animal_home_page.php?mypet=Cat">Cat</a> person</p>
> <p>I am a <a href="animal_home_page.php?mypet=Dog">Dog</a> person </p>
> </body>
> </html>
>
>
> ******************
> ****Second Page****
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
> </head>
>
> <body>
> <h1>The <?php echo $_GET['mypet']; ?> Person Home Page?</h1>
> <p>I am a <?php echo $_GET['mypet']; ?> person. </p>
> </body>
> </html>
>
> **********************
>
> Many thank
>
> J
>
>



Reply With Quote
  #3 (permalink)  
Old 06-11-2004
Ian Pawson
 
Posts: n/a
Default Re: Newbie Question - PHP variable not working

There is also a 'special' syntax for this using the = sign
<?=$mypet ?>

"Molle" <6mollen@zonnet.nl> wrote in message
news:aOkyc.285$by6.15068@zonnet-reader-1...
> Hello J,
> This is the right syntax:
>
> <h1>The <?php print $mypet; ?> Person Home Page?</h1>
>
> Goodluck,
>
> Molle
>
>
> "JD" <nospam@toomuchspam.com> schreef in bericht
> news:J9kyc.79605$wd7.15360@front-1.news.blueyonder.co.uk...
> > Hello,
> >
> > I'm just starting out using PHP with DWMX2004, and have hit a stumbling
> > block whilst trying to run a very simple excercise. It's probably

> something
> > quite silly that I'm missing, but having read tutorials etc again and

> again,
> > I can't see what it is. I'm hoping someone might be able direct me to

what
> > is wrong.
> >
> > Basically I have a form which asks the user to select one of two

possible
> > states for a variable, mypet. When the type of pet is selected, an new

> page
> > opens, which is supposed to show what type of pet was selected, ...but

it
> > doesn't.
> >
> > When the second page opens, the line:-
> > http://localhost/newland/animal_home_page.php?mypet=Cat does appear in

the
> > URL bar, which looks to me like the variable is getting assigned. But

only
> a
> > blank space appears in the page text where the animal name is supposed

to
> > be.
> >
> > I've included a copy of the source below. I hope someone may be able to

> see
> > where I'm going wrong.
> >
> > I have Apache 2.0.47 & PHP 4.3.3 installed on a Windows XP Pro machine
> > configured as a local host.
> >
> >
> > **** First Page ****
> >
> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> > <html xmlns="http://www.w3.org/1999/xhtml">
> > <head>
> > <title>Untitled Document</title>
> > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"

/>
> > </head>
> >
> > <body>
> > <h1>Are You a Cat Person or a Dog Person?</h1>
> > <p>I am a <a href="animal_home_page.php?mypet=Cat">Cat</a> person</p>
> > <p>I am a <a href="animal_home_page.php?mypet=Dog">Dog</a> person </p>
> > </body>
> > </html>
> >
> >
> > ******************
> > ****Second Page****
> >
> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> > <html xmlns="http://www.w3.org/1999/xhtml">
> > <head>
> > <title>Untitled Document</title>
> > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"

/>
> > </head>
> >
> > <body>
> > <h1>The <?php echo $_GET['mypet']; ?> Person Home Page?</h1>
> > <p>I am a <?php echo $_GET['mypet']; ?> person. </p>
> > </body>
> > </html>
> >
> > **********************
> >
> > Many thank
> >
> > J
> >
> >

>
>



Reply With Quote
  #4 (permalink)  
Old 06-11-2004
Tom Thackrey
 
Posts: n/a
Default Re: Newbie Question - PHP variable not working



On 11-Jun-2004, "Molle" <6mollen@zonnet.nl> wrote:

> > <h1>The <?php echo $_GET['mypet']; ?> Person Home Page?</h1>
> > <p>I am a <?php echo $_GET['mypet']; ?> person. </p>


> This is the right syntax:
>
> <h1>The <?php print $mypet; ?> Person Home Page?</h1>


Actually, not only is his syntax correct it has the advantage of working
with register_globals off.

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to jamesbutler@willglen.net (it's reserved for spammers)
Reply With Quote
  #5 (permalink)  
Old 06-13-2004
PhilM
 
Posts: n/a
Default Re: Newbie Question - PHP variable not working



> There is also a 'special' syntax for this using the = sign
> <?=$mypet ?>
>


this, in my experience, forces the script to fail if short tags is disabled
in php.ini.

PhilM


Reply With Quote
  #6 (permalink)  
Old 06-13-2004
JD
 
Posts: n/a
Default Re: Newbie Question - PHP variable not working

Hi Guys,

Thanks for the pointers. I eventually tracked down the problem to being how
PHP was configured. Once I added the "AddType Application/x-httpd-php .php"
to the config file, it worked fine. ...The book I was working with did not
mention anything about having to have this command in the file!

Many thanks, J

"JD" <nospam@toomuchspam.com> wrote in message
news:J9kyc.79605$wd7.15360@front-1.news.blueyonder.co.uk...
> Hello,
>
> I'm just starting out using PHP with DWMX2004, and have hit a stumbling
> block whilst trying to run a very simple excercise. It's probably

something
> quite silly that I'm missing, but having read tutorials etc again and

again,
> I can't see what it is. I'm hoping someone might be able direct me to what
> is wrong.
>
> Basically I have a form which asks the user to select one of two possible
> states for a variable, mypet. When the type of pet is selected, an new

page
> opens, which is supposed to show what type of pet was selected, ...but it
> doesn't.
>
> When the second page opens, the line:-
> http://localhost/newland/animal_home_page.php?mypet=Cat does appear in the
> URL bar, which looks to me like the variable is getting assigned. But only

a
> blank space appears in the page text where the animal name is supposed to
> be.
>
> I've included a copy of the source below. I hope someone may be able to

see
> where I'm going wrong.
>
> I have Apache 2.0.47 & PHP 4.3.3 installed on a Windows XP Pro machine
> configured as a local host.
>
>
> **** First Page ****
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
> </head>
>
> <body>
> <h1>Are You a Cat Person or a Dog Person?</h1>
> <p>I am a <a href="animal_home_page.php?mypet=Cat">Cat</a> person</p>
> <p>I am a <a href="animal_home_page.php?mypet=Dog">Dog</a> person </p>
> </body>
> </html>
>
>
> ******************
> ****Second Page****
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
> </head>
>
> <body>
> <h1>The <?php echo $_GET['mypet']; ?> Person Home Page?</h1>
> <p>I am a <?php echo $_GET['mypet']; ?> person. </p>
> </body>
> </html>
>
> **********************
>
> Many thank
>
> J
>
>



Reply With Quote
  #7 (permalink)  
Old 06-14-2004
Alvaro G Vicario
 
Posts: n/a
Default Re: Newbie Question - PHP variable not working

*** JD wrote/escribió (Sun, 13 Jun 2004 18:13:02 +0100):
> Thanks for the pointers. I eventually tracked down the problem to being how
> PHP was configured. Once I added the "AddType Application/x-httpd-php .php"
> to the config file, it worked fine. ...The book I was working with did not
> mention anything about having to have this command in the file!


That means your pages were not even being parsed. We were mislead because
you said "only a blank space appears in the page text". Actually, it seems
you didn't check the source code of the HTML page: you should see "<?php
echo $_GET['mypet']; ?>", not a blank space.

--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Reply With Quote
  #8 (permalink)  
Old 06-20-2004
Rocky
 
Posts: n/a
Default Re: Newbie Question - PHP variable not working

In article <LVlyc.83797$si6.38522@newssvr25.news.prodigy.com> ,
use.signature@nospam.com says...
>
>
> On 11-Jun-2004, "Molle" <6mollen@zonnet.nl> wrote:
>
> > > <h1>The <?php echo $_GET['mypet']; ?> Person Home Page?</h1>
> > > <p>I am a <?php echo $_GET['mypet']; ?> person. </p>

>
> > This is the right syntax:
> >
> > <h1>The <?php print $mypet; ?> Person Home Page?</h1>

>
> Actually, not only is his syntax correct it has the advantage of working
> with register_globals off.
>


The OP's code worked fine with my setup on XP Home.

JD ... suggest you move away from Apache2 and go back to Apache1.

Rocky

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:11 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0