"Hello World" php test not displaying correctly. Cant get PHP code to "POST" either
Posted by: jboyette (---.carolina.res.rr.com)
Date: February 09, 2014 05:08AM

Version of Operating system Windows 7 Home Premium (64 Bit)
Version of Wamp Server installed Wamp 2.4
Version of Apache you are running Apache 2.4.4 (Win 32
Version of MySQL you are running MySQL 5.6.12
Version of PHP you are running PHP 5.4.16


Hello World Test Problem:

Installed Wamp 2.4 and went through the Sticky Forum "Wampserver 2.4 What to do after Installing" and did all of that.

testing out the simple "hello world" php test with this code:

<html>
<head>
<title>First PHP Page</title>
</head>
<body>
<?php
echo '<h1>Hello, world!</h1>';
?>
</body>
</html>


Produces this text on browser (Mozilla Firefox 27.0): Hello, world!'; ?>

On Internet Explorer 9.0.8112.16421 it will not open at all.


$_POST not displaying values, instead variable names Problem


I continued on with using this "Head First PHP&MySQL" book with an .html and .php file downloaded from their website for testing:

.HTML Code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"[www.w3.org];
<html xmlns="[www.w3.org]; 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 method="post" action="report.php">
<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>


.PHP Code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"[www.w3.org];
<html xmlns="[www.w3.org]; 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>
</head>
<body>
<h2>Aliens Abducted Me - Report an Abduction</h2>

<?php

session_start();
$name = $_POST['firstname'] . ' ' . $_POST['lastname'];
$when_it_happened = $_POST['whenithappened'];
$how_long = $_POST['howlong'];
$how_many = $_POST['howmany'];
$alien_description = $_POST['aliendescription'];
$what_they_did = $_POST['whattheydid'];
$fang_spotted = $_POST['fangspotted'];
$email = $_POST['email'];
$other = $_POST['other'];

$to = 'owen@aliensabductedme.com';
$subject = 'Aliens Abducted Me - Abduction Report';
$msg = "$name was abducted $when_it_happened and was gone for $how_long.\n" .
"Number of aliens: $how_many\n" .
"Alien description: $alien_description\n" .
"What they did: $what_they_did\n" .
"Fang spotted: $fang_spotted\n" .
"Other comments: $other";
mail($to, $subject, $msg, 'From:' . $email);

echo 'Thanks for submitting the form.<br />';
echo 'You were abducted ' . $when_it_happened;
echo ' and were gone for ' . $how_long . '<br />';
echo 'Number of aliens: ' . $how_many . '<br />';
echo 'Describe them: ' . $alien_description . '<br />';
echo 'The aliens did this: ' . $what_they_did . '<br />';
echo 'Was Fang there? ' . $fang_spotted . '<br />';
echo 'Other comments: ' . $other . '<br />';
echo 'Your email address is ' . $email;
?>

</body>
</html>


HTML form displays properly and hitting the "submit" button produces this text on browser (Mozilla Firefox 27.0):


Aliens Abducted Me - Report an Abduction
'; echo 'You were abducted ' . $when_it_happened; echo ' and were gone for ' . $how_long . '
'; echo 'Number of aliens: ' . $how_many . '
'; echo 'Describe them: ' . $alien_description . '
'; echo 'The aliens did this: ' . $what_they_did . '
'; echo 'Was Fang there? ' . $fang_spotted . '
'; echo 'Other comments: ' . $other . '
'; echo 'Your email address is ' . $email; ?>

shows .php variable names versus values inputted on html form as well as the echo's.

On Internet Explorer 9.0.8112.16421 .html displays properly but hitting "submit" button will then ask to open the .php file which does not occur.



any idea on what I need to do to get this working correctly? thanks

Options: ReplyQuote
Re: "Hello World" php test not displaying correctly. Cant get PHP code to "POST" either
Posted by: jboyette (---.carolina.res.rr.com)
Date: February 09, 2014 05:29AM

ok, I redownloaded a 64 bit version of wamp server so now im running

Version of Apache you are running Apache 2.4.4 (Win 64 bit). still having the same issue although I havnt made the changes from the Sticky Forum "Wampserver 2.4 What to do after Installing"

Options: ReplyQuote
Re: "Hello World" php test not displaying correctly. Cant get PHP code to "POST" either
Posted by: Kirk (---.dhcp.stcd.mn.charter.com)
Date: February 09, 2014 05:11PM

Are you publishing your page(s) as PHP pages and not HTML pages? Whenever you have PHP code on a page, it must be published as a PHP page.

Options: ReplyQuote
Re: "Hello World" php test not displaying correctly. Cant get PHP code to "POST" either
Posted by: jboyette (---.carolina.res.rr.com)
Date: February 10, 2014 12:20AM

First, im pretty green on all things html and php. Can you describe what is meant by "publishing as php?

The hello world document im loading into a browser is a .php extension (code below again for reference). I am opening this file in Mozilla via the tool bar menu (File>>>Open File) and then browsing for the hello.php file


the url displays this: file:///C:/wamp3/www/hello.php

text is this Hello, world!'; ?>


Is there something else I need to do to "publish"?



Hello World Code (Hello.php file name)

<html>
<head>
<title>First PHP Page</title>
</head>
<body>
<?php
echo '<h1>Hello, world!</h1>';
?>
</body>
</html>


thanks

Options: ReplyQuote
Re: "Hello World" php test not displaying correctly. Cant get PHP code to "POST" either
Posted by: RiggsFolly (---.ppp.as43234.net)
Date: February 10, 2014 01:13AM

Are you doubleclicking the first file in Explorer??

If so DONT.

Enter the url into the browser address bar directly.

So if you put these files in \wamp\www\file1.html then enter 'http://localhots/file1.html'


PHP Code has to be observed by Apache to be compiled and run, if you double click on the file in explorer it does not get passed through Apache at all.!!!!

You just installed a webs server, so why not use it!!

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: "Hello World" php test not displaying correctly. Cant get PHP code to "POST" either
Posted by: jboyette (---.carolina.res.rr.com)
Date: February 10, 2014 01:43AM

ah, I see now. things are working as expected now. One would think if I was by passing the webserver entirely it wouldnt read any of the php script. Er maybe just someone like myself with little knowledge would think that.

Anyways I appear to be good to go now. Thanks for the help!

Options: ReplyQuote
Re: "Hello World" php test not displaying correctly. Cant get PHP code to "POST" either
Posted by: RiggsFolly (---.ppp.as43234.net)
Date: February 10, 2014 12:37PM

No,

If you run direct to the browser it, as it always does can read and convert HTML.

However you have to passs your request via Apache, as it is apache that see's the <?php ?> start and end tags and therefore decides to pass the whole file to the PHP interpreter. PHP then gets to compile and run the PHP and when its done it passes the results back to Apache to send to the browser.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote


Sorry, only registered users may post in this forum.