Jump to content


Photo

Help with simple script I can't get to work!


  • Please log in to reply
4 replies to this topic

#1 ice1000

ice1000
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 08 July 2006 - 05:23 PM

I'm using XAMPP for Windows. I'm working through a book 'PHP and MySQL for Dynamic Web Sites'. Chapter 2 is about handling forms.

I created the followng form:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	<title>HTML Form</title>
</head>
<body>

<!-- Script 2.1 - form.html -->

<form action="handle_form.php" method="post">

<fieldset><legend>Enter your information in the form below:</legend>

<p align="left"><b>Name:</b> <input type="text" name="name" size="20" maxlength="40" /></p>

<p align="left"><b>Email Address:</b> <input type="text" name="email" size="40" maxlength="60" /> </p>

<p align="left"><b>Gender:</b> <input type="radio" name="gender" value="M" /> Male <input type="radio" name="gender" value="F" /> Female</p>

<p align="left"><b>Age:</b> 
<select name="age">
	<option value="0-30">Under 30</option>
	<option value="30-60">Betweeen 30 and 60</option>
	<option value="60+">Over 60</option>
</select></p>

<p align="left"><b>Comments:</b> <textarea name="comments" rows="3" cols="50"></textarea></p>

</fieldset>

<div align="center"><input type="submit" name="submit" value="Submit Information" /></div>

</form><!-- End of Form -->

</body>
</html>

and the handle_form.php is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	<title>Form Feedback</title>
</head>
<body>
<?php

echo "Thank  you, <b>$name</b> for the following comments:<br /><tt>$comments</tt><p>We will reply to you at <i>$email</i>.</p>";

?>
</body>
</html>


I don't get the string value with the variable names. I get this:

$name for the following comments:
$comments

We will reply to you at $email.
"; ?>


My register_globals are on. What am I missing?

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 08 July 2006 - 05:35 PM

How did you invoke the HTML file that displays the form? Double clicking the file or using a URL of the form http://localhost/form.html
If it was by double clicking, then that is your problem.

Ken

#3 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 08 July 2006 - 05:38 PM

There's something strange here. Are you sure you're showing us the correct output display?

The "Thank you, " part is missing. The output is also displaying this part of your PHP code:  "; ?>

Is this just a mistake on your part as you were posting this into this forum?

If these variables aren't initialized then the output would be something like this:

Thank you, for the following comments:

We will reply to you at .

Not what you're showing. It could mean that PHP is not installed properly or server not setup to recognize PHP. Write the following in a separate script and run it to see what your PHP settings are:

<?PHP
phpinfo();
?>

Please note that it's best to keep register_globals off and program accordingly. That means using $_POST in this case to access your form values. See:

http://us2.php.net/m...d.variables.php



#4 ice1000

ice1000
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 08 July 2006 - 09:17 PM

That was it. I was double clicking the form instead of typing in the path.

Can someone explain why double clickng does not work?

Thanks for the tip on turning off register_globals.

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 08 July 2006 - 09:21 PM

Double clicking causes the browser to read the HTML code directly and it makes the URI start with "file:///". Then then final URL of the actioin will also start with "file:///" instead of "http://". A URL starting with "file:///" is not processed by the webserver, so PHP is never invoked to process the script.  "file:///" runs on the client, but PHP needs to be processed on the server via the web server process. Even if the client and the server are the same machine.

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users