Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 17th, 2004, 12:02 AM
Registered User
 
Join Date: Aug 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to urbanTaz
Default My scripts are not working, why?

I I wanted to learn php programming, so I purchase Beginning PHP 4.
By the way Great book!
But when I began writing out some of the example scripts, and loading them into my web sever. The example scripts did not work.
The examples scripts in the chapter 1 and 2 worked just fine, but the example scripts from chapter 3 and up just does not work.
Here are some of the example script, below:

HTML Script:
<html>
<head></head>
<body>
<form method=post action="radio.php">
What is the state of Portugal?
<br>
<br>
<input name="Question1" type="radio" value="Porto">Porto
<br>
<input name="Question1" type="radio" value="Lisbon">Lisbon
<br>
<input name="Question1" type="radio" value="Madrid">Madrid
<br>
<br>
<input type="Submit">
</form>
</body>
</html>

PHP Script:
<html>
<head></head>
<body>
<?php
echo "You have selected the answer: $Question1";
?>
</body>
</html>

Or see it live: http://www.urbani.ws/php/radio.htm

Please help; I am starting to get discouraged.

 
Old August 17th, 2004, 12:20 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to qazi_nomi
Default

Dear you should use echo like this

echo "You have selected the answer:" $Question1;





Numan
--------------------------------------------------
Love is the most precious thing of this world. So find and grab it!
 
Old August 17th, 2004, 05:05 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No, that makes no difference, at all.

This is register_globals (again). Global variables (the values sent from your form) are no longer available by default within PHP and haven't been for several years. Wiley continue to publish the book in its original edition, despite this fact, and the data within it is therefore out of date. Hey, who am I to say they're wrong? they're making money, and we went bankrupt: so who am I to judge :)?

TO EXPLAIN:
You must now refer to variables sent from a HTML form via their global array values. In your code, above, replave $Question1 with $_POST['Question1'].

Try this:
http://p2p.wrox.com/search.asp?mode=...lobals&x=0&y=0

...and this:
http://p2p.wrox.com/archive/site_sea...gister_globals
 
Old August 22nd, 2004, 03:09 PM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

so the script should be as follows?:

HTML Script:
<html>
<head></head>
<body>
<form method=post action="radio.php">
What is the state of Portugal?
<br>
<br>
<input name="Question1" type="radio" value="Porto">Porto
<br>
<input name="Question1" type="radio" value="Lisbon">Lisbon
<br>
<input name="Question1" type="radio" value="Madrid">Madrid
<br>
<br>
<input type="Submit">
</form>
</body>
</html>

PHP Script:
<html>
<head></head>
<body>
<?php
echo "You have selected the answer: $_POST['Question1']";
?>
</body>
</html>

I'm learning PHP too, thanks for putting up with us "beginners"!

 
Old August 23rd, 2004, 04:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That'll work if you concatentate your reference to the the $_POST variable onto the end of your string - i.e.:

echo 'You have selected the answer: ' . $_POST['Question1'];

This is the most efficient approach, since PHP carrys out less processing when it encounters single-quoted strings, as opposed to double quoted ones.

If you want to make use of PHP's advanced parsing ability WRT how it handles double-quoted strings, you could encapsulate the refereence to the $_POST variable within the string, but you'll have to surround it in {} brackets - i.e.:

echo "You have selected the answer: {$_POST['Question1']}";

...so in actual fact you gain nothing, other than a demonstration of how very clever the PHP team are at building a flexible, fast language processor :).

If you use method="get", instead, for your form, the value will be in the $_GET[] array, of course.

As a added suggestion, I'd advise you to quote all your HTML element attributes (i.e. method="post", in your HTML quoted above), since A) elements that aren't quoted are not strictly correct HTML markup, and B) pages without quoted attributes will not work as expected in old browsers like Netscape 4.x, for precisely that reason.

Admittedly, Netscape 4 has now been replaced by something called 'Internet Explorer' as everyone's favourite Broken Grey rectangle That You Have To Provide Gruesome Hacks For... but still, in this respect Netscape 4 fails because of its adherance to Web standards, and not despite them (which is usually the case).

Take it easy,
Dan
 
Old August 26th, 2004, 04:57 AM
Authorized User
 
Join Date: Aug 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I do have similar problem. On beginning I thought it is gone be only global variables, but in my case I think is problem with settings. Do any of you have any suggestions?:(

P.T.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Sql Scripts webnathan ASP.NET 1.0 and 1.1 Basics 2 November 16th, 2007 05:50 AM
Scripts Format rgerald SQL Server 2000 1 July 10th, 2003 12:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.