hugo Posted June 26, 2014 Share Posted June 26, 2014 For some reason XAMPP Apache is no longer working--it was working before. To be sure, I downloaded Larry's HTML and PHP scripts (from OReilly Website) and tested them; and the output I received in my browser was: Thank you, $title $name, for your comments. You stated that you found this example to be '$response' and added:$comments "; ?> The HTML file downloaded is Script_03_01.html: <!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" xml:lang="en" lang="en"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Feedback Form</title></head><body><!-- Script 3.1 - feedback.html --><div><p>Please complete this form to submit your feedback:</p><form action="handle_form.php"> <p>Name: <select name="title"> <option value="Mr.">Mr.</option> <option value="Mrs.">Mrs.</option> <option value="Ms.">Ms.</option> </select> <input type="text" name="name" size="20" /></p> <p>Email Address: <input type="text" name="email" size="20" /></p> <p>Response: This is... <input type="radio" name="response" value="excellent" /> excellent <input type="radio" name="response" value="okay" /> okay <input type="radio" name="response" value="boring" /> boring</p> <p>Comments: <textarea name="comments" rows="3" cols="30"></textarea></p> <input type="submit" name="submit" value="Send My Feedback" /></form></div></body></html> The downloaded PHP file is Script_03_03.php: <!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" xml:lang="en" lang="en"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Your Feedback</title></head><body><?php // Script 3.3 handle_form.php// This page receives the data from feedback.html.// It will receive: title, name, email, response, comments, and submit in $_POST.// Create shorthand versions of the variables:$title = $_POST['title'];$name = $_POST['name'];$response = $_POST['response'];$comments = $_POST['comments'];// Print the received data:print "<p>Thank you, $title $name, for your comments.</p><p>You stated that you found this example to be '$response' and added:<br />$comments</p>";?></body></html> I'm also not sure if this is relevant but I'm not currently using a genuine Windows 7 version (which was working just fine before). Can someone please help? Thanks in advance. Link to comment Share on other sites More sharing options...
HartleySan Posted June 26, 2014 Share Posted June 26, 2014 Make a new PHP file called test.php and then add the following to the file and try to run it: <?php php_info(); If that works, then the installation is fine. It seems to me that you're trying to run an HTML file as a PHP file, but I could be wrong. Please let us know what you find. Thanks. Link to comment Share on other sites More sharing options...
hugo Posted June 26, 2014 Author Share Posted June 26, 2014 Hi Hartley, Yes I ran php_info(); and all the information is shown neatly in a long grid. I'm still stumped as to why the php output is like that. I double clicked the HTML form which opens in Mozilla, then I filled in the form and pressed the submit button. The php output that returns is strange. Can you please help? Link to comment Share on other sites More sharing options...
HartleySan Posted June 26, 2014 Share Posted June 26, 2014 You are running your files through localhost, and not just opening them in the browser, correct? Link to comment Share on other sites More sharing options...
hugo Posted June 27, 2014 Author Share Posted June 27, 2014 Yeah, I just tried typing in http://localhost/script_03_01.html into my browser, then I filled out the form and got this output: Notice: Undefined index: title in C:\xampp\htdocs\handle_form.php on line 15Notice: Undefined index: name in C:\xampp\htdocs\handle_form.php on line 16Notice: Undefined index: response in C:\xampp\htdocs\handle_form.php on line 17Notice: Undefined index: comments in C:\xampp\htdocs\handle_form.php on line 18 Thank you, , for your comments. You stated that you found this example to be '' and added: I'm kinda confused now: Am I supposed to open the HTML file in my browser then fill out the form and submit it? Or, am I supposed to run the HTML through local host as well? (as well at the PHP file which I have been running through local host--to test if I could simply send html created by PHP to the browser). In anycase, I can't seem to get the scripts to work. I'm still stumped. Link to comment Share on other sites More sharing options...
HartleySan Posted June 27, 2014 Share Posted June 27, 2014 My guess would be that your form element doesn't have the method="post" attribute, and as a result, the form is being submitted via the GET method, thus causing the $_POST superglobal to not be populated, thus leading to those errors you stated. Try adding the following code right above where you are attempting to set those four PHP variables to either confirm or deny my suspicions: echo '<pre>'; print_r($_GET); print_r($_POST); echo '</pre>'; You can also easily confirm if the GET method is being used by seeing if all the form data is placed in the URL bar as URL parameters upon form submission. Link to comment Share on other sites More sharing options...
hugo Posted June 27, 2014 Author Share Posted June 27, 2014 It works now: I was missing the method. Thanks for catching that mistake Hartley. However, it was strange-all my scripts, not just the one I posted was spitting out only the PHP source code. My scripts work now although I have no idea what I did. I tried shutting off and turning back on XAMPP and also made sure to use Save As in Notepad++; perhaps these steps helped? I don't know. I'm so glad the scripts are working now, phew! Link to comment Share on other sites More sharing options...
HartleySan Posted June 27, 2014 Share Posted June 27, 2014 If the PHP code was all printing out directly, then either: You were not running the script through localhost, or More likely, you were running the PHP script as an HTML file. There is no other explanation. Either way, if it works now and you know what you did wrong, don't sweat it. 1 Link to comment Share on other sites More sharing options...
Recommended Posts