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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 > > |
|
|||
|
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 > > > > > > |
|
|||
|
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) |
|
|||
|
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 > > |
|
|||
|
*** 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 -- |
|
|||
|
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 |