debweb84 Posted May 20, 2009 Share Posted May 20, 2009 Hi all, I am NOT a programmer by trade and am trying to teach myself PHP, so if i mess up a bit on my terminologies, apologies! i'm working with a manual "Head First PHP and MYSQL" and on their web site they provide some practice documents/sites to toy with as you learn...i created my own root folder, and apache/php by the looks of things and by my testphp.doc seems to be running...however, when i drop my .html and .php docs provided by my manual in this root folder (which i guess means they are 'on the server') and when i open the .html doc in my browser (in this html doc i put in the 'form' tag that the action should be connected to my .php doc) my "result" when i click "submit" on the form is all cokamaymeed (like echos, dollar signs, etc) instead of being "clean" and normal looking (like what the client should see)...indicating that the php isn't running i guess...? any suggestions on why this would be? like why a site with php wouldnt run properly on a server with php, thats by all indications working? again sorry for my lack of understanding of any terminologies! help, please, anyone! Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 20, 2009 Share Posted May 20, 2009 Do I understand that a .php file works, but not the code from your tutorial? Post the contents of the .php file, including the opening php tags in the file. Quote Link to comment Share on other sites More sharing options...
debweb84 Posted May 20, 2009 Author Share Posted May 20, 2009 copied are my two files, one an html doc and the other the accompanying php doc on which the html is supposed to perform the 'action' on when put into the server folder... however, when both are in my root doc (server) folder, and when i open the html doc from there in my browser and try out the form and submit it, the result shows that the php hasn't worked as it's all messed uplooking. here is my report.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>Aliens Abducted Me - Report an Abduction</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h2>Aliens Abducted Me - Report an Abduction</h2> <p>Share your story of alien abduction:</p> <form action= "report.php" method= "post"> <---here is the line where i tell my html to reference the report.php below---> <label for="firstname">First name:</label> <input type="text" id="firstname" name="firstname" /><br /> <label for="lastname">Last name:</label> <input type="text" id="lastname" name="lastname" /><br /> <label for="email">What is your email address?</label> <input type="text" id="email" name="email" /><br /> <label for="whenithappened">When did it happen?</label> <input type="text" id="whenithappened" name="whenithappened" /><br /> <label for="howlong">How long were you gone?</label> <input type="text" id="howlong" name="howlong" /><br /> <label for="howmany">How many did you see?</label> <input type="text" id="howmany" name="howmany" /><br /> <label for="aliendescription">Describe them:</label> <input type="text" id="aliendescription" name="aliendescription" size="32" /><br /> <label for="whattheydid">What did they do to you?</label> <input type="text" id="whattheydid" name="whattheydid" size="32" /><br /> <label for="fangspotted">Have you seen my dog Fang?</label> Yes <input id="fangspotted" name="fangspotted" type="radio" value="yes" /> No <input id="fangspotted" name="fangspotted" type="radio" value="no" /><br /> <img src="fang.jpg" width="100" height="175" alt="My abducted dog Fang." /><br /> <label for="other">Anything else you want to add?</label> <textarea id="other" name="other"></textarea><br /> <input type="submit" value="Report Abduction" name="submit" /> </form> </body> </html> here is my accompanying script: <html> <head> <title>Aliens Abducted Me - Report an Abduction</title> </head> <body> <h2>Aliens Abducted Me - Report an Abduction</h2> <?php $when_it_happened = $_POST['whenithappened']; $how_long = $_POST['howlong']; $alien_description = $_POST['description']; $fang_spotted = $_POST['fangspotted']; $email = $_POST['email'] echo 'Thanks for submitting the form.<br />'; echo 'You were abducted ' . $when_it_happened; echo ' and were gone for ' . $how_long . '<br />'; echo 'Describe them: ' . $alien_description . '<br />'; echo 'Was Fang there? ' . $fang_spotted . '<br />'; echo 'Your email address is ' . $email; ?> </body> </html> i'm worried that the problem may be, if not with the code, with the server/folder situation i've got set up? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 20, 2009 Share Posted May 20, 2009 Where are you saving your html/php files to? By default you must save them in Apaches htdocs folder (eg C:/path/to/Apache/htdocs) How are you running your .html/.php files? If you have Apache installed and configured correctly with PHP make sure you're going to http://localhost/ PHP is a server side language. Web browsers do not understand PHP, only HTML/CSS/JS etc. Quote Link to comment Share on other sites More sharing options...
debweb84 Posted May 20, 2009 Author Share Posted May 20, 2009 wildteen: everything is saved to my htdocs, and i'm clear that everything runs server-side within my htdocs folder is my aliens folder, and in aliens are my report.html, report.php, image, css, etc i tried what you said about opening it via localhost/aliens/report.html this time though, in my browser, instead of the garbled php output when i submit the form i get a blank page on my result page (url of which is http://localhost/aliens/report.php) so it went from report.html to report.php which is good i am guessing, however, the output is blank for some reason! do you see any scripting/coding errors by any chance? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 21, 2009 Share Posted May 21, 2009 When you go to report.php what do you see when you right click and select view source? If the source code is blank then it means there is an error in your code preventing the script from running. In this case I would recommend you to turn display_errors to On and setting error_reporting to E_ALL. Save the php.ini and restart Apache for changes to take effect. Errors should now be displayed during run time. However if you see your PHP source code (which you shouldn't be able to do) it means Apaches isn't configured correctly. Quote Link to comment Share on other sites More sharing options...
debweb84 Posted May 22, 2009 Author Share Posted May 22, 2009 K, think we may be on to something! Apache is configed correctly. when I clicked submit on my form on the browser after turning that display_errors to ON (error_reporting was already E_ALL) the result was this: Parse error: parse error in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\aliens\report.php on line 27 When I go to 'line 27' in Note or PSpad though I don't see anything wrong: echo 'Thanks for submitting the form.<br />'; Here is the surrounding script again: <html> <head> <title>Aliens Abducted Me - Report an Abduction</title> </head> <body> <h2>Aliens Abducted Me - Report an Abduction</h2> <?php $when_it_happened = $_POST['whenithappened']; $how_long = $_POST['howlong']; $alien_description = $_POST['description']; $fang_spotted = $_POST['fangspotted']; $email = $_POST['email'] echo 'Thanks for submitting the form.<br />'; echo 'You were abducted ' . $when_it_happened; echo ' and were gone for ' . $how_long . '<br />'; echo 'Describe them: ' . $alien_description . '<br />'; echo 'Was Fang there? ' . $fang_spotted . '<br />'; echo 'Your email address is ' . $email; ?> </body> </html> Do you see anything? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 23, 2009 Share Posted May 23, 2009 You left off the semi-colon at the end of this line $email = $_POST['email'] Quote Link to comment Share on other sites More sharing options...
debweb84 Posted May 24, 2009 Author Share Posted May 24, 2009 lovely! it's actually worked; the output that's supposed to be there according to my book IS there However: This error comes up: Notice: Undefined index: description in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\aliens\report.php on line 21 Notice: Undefined index: fangspotted in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\aliens\report.php on line 23 above that desired output which appears on my report.php in the browser. I turned my display settings in php.ini back to Off but not sure how to make this 'Undefined index' notices disappear as well! Quote Link to comment Share on other sites More sharing options...
debweb84 Posted May 24, 2009 Author Share Posted May 24, 2009 nevermind: actually searched this on the Net, added this: $ebits = ini_get('error_reporting'); error_reporting($ebits ^ E_NOTICE); so it's all good. Thanks for all your help! Quote Link to comment 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.