Jump to content

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


ice1000

Recommended Posts

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:

[code]<!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>[/code]

and the handle_form.php is:

[code]<!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>[/code]


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

[quote]$name for the following comments:
$comments

We will reply to you at $email.
"; ?>[/quote]

My register_globals are on. What am I missing?
Link to comment
Share on other sites

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/manual/en/reserved.variables.php

Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.