ice1000 Posted July 8, 2006 Share Posted July 8, 2006 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><?phpecho "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:$commentsWe will reply to you at $email."; ?>[/quote]My register_globals are on. What am I missing? Quote Link to comment https://forums.phpfreaks.com/topic/14033-help-with-simple-script-i-cant-get-to-work/ Share on other sites More sharing options...
kenrbnsn Posted July 8, 2006 Share Posted July 8, 2006 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.htmlIf it was by double clicking, then that is your problem.Ken Quote Link to comment https://forums.phpfreaks.com/topic/14033-help-with-simple-script-i-cant-get-to-work/#findComment-54843 Share on other sites More sharing options...
toplay Posted July 8, 2006 Share Posted July 8, 2006 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:<?PHPphpinfo();?>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 Quote Link to comment https://forums.phpfreaks.com/topic/14033-help-with-simple-script-i-cant-get-to-work/#findComment-54846 Share on other sites More sharing options...
ice1000 Posted July 8, 2006 Author Share Posted July 8, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14033-help-with-simple-script-i-cant-get-to-work/#findComment-54925 Share on other sites More sharing options...
kenrbnsn Posted July 8, 2006 Share Posted July 8, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/14033-help-with-simple-script-i-cant-get-to-work/#findComment-54927 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.