Problems getting PHP to work

Problems with the Mac OS X version of XAMPP, questions, comments, and anything related.

Problems getting PHP to work

Postby Tofer » 18. March 2019 16:52

I am a newbie to XAMPP, but I have plenty of old-school programming experience.
I have installed XAMPP 7.3 on Mac OS Mojave. I pasted sample HTML code from W3C lessons, and it works great.
I pasted some simple "Hello World" html and php code, and named the two files using .html and .php extensions respectively.
I saved the two files into the same folder.
When I execute the html, which contains two simple text input boxes and one Submit button, the php file content is displayed in the browser, but the php code does not execute.
Have I missed a step in the installation ?
Here is the welcome.html file:
<!document html>
<html>
<body>

<form action="welcome.php" method="post">
Your Name: <input type="text" name="name"><br>
Your E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>

Here is the welcome.php file:
<html>
<body>

Welcome Back <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>

</body>
</html>

Thanks in advance for your assistance
Tofer
 
Posts: 3
Joined: 18. March 2019 16:24
XAMPP version: 7.3.1
Operating System: Mac OS Mojave 10.14.3

Re: Problems getting PHP to work

Postby Altrea » 19. March 2019 07:37

Did you request the html form?
Which URL did you type in your browser?
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 9649
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Problems getting PHP to work

Postby Tofer » 19. March 2019 11:35

I saved the Welcome.html and the Welcome.php files in a folder called ‘MyApp’ on my Desktop
I then used Safari (I also tried this on Chrome), with the url
‘File://users/myname/desktop/myapp/welcome.html’
(I assume this what you mean by “requesting the form”)
The html form displayed properly, and I was able to enter data into the two input fields.
Then when I click the button, the browser only displays the contents of the Welcome,php file as text, without executing the code.

So it seems that the browser finds both the .html and the .php files

What installation steps have I missed that apparently prevents the php code from executing ?
Tofer
 
Posts: 3
Joined: 18. March 2019 16:24
XAMPP version: 7.3.1
Operating System: Mac OS Mojave 10.14.3

Re: Problems getting PHP to work

Postby Nobbie » 19. March 2019 12:19

Tofer wrote:I then used Safari (I also tried this on Chrome), with the url
‘File://users/myname/desktop/myapp/welcome.html’


Thats badly wrong, the browser cannot execute PHP, that is executed by the server (i.e. Apache/PHP) and in order to request the document from the local Xampp server, you MUST enter http://localhost/blablabla

At next, you cannot store the welcome.html onto your desktop or whereever you want, you must put it into the DocumentRoot of your Apache installation. Depending on your Xampp installation (either VM or non-VM) this is either /opt/lampp/htdocs (in a VirtualMachine) or it is at /Applications/XAMPP/xamppfiles/htdocs. For example, store welcome.html into /Applications/XAMPP/xamppfiles/htdocs/welcome.html, also put your PHP scripts into /Applications/XAMPP/xamppfiles/htdocs and finally enter http://localhost/welcome.html

Last not least you really should go for some tutorials about Xampp, Apache, PHP etc., it is a bad idea not to read any documentation before starting to work with such a sophistic software like an Apache Webserver.

Tofer wrote:What installation steps have I missed that apparently prevents the php code from executing ?


You missed to read ANY documentation about webservers.
Nobbie
 
Posts: 10965
Joined: 09. March 2008 13:04

Re: Problems getting PHP to work

Postby Tofer » 19. March 2019 22:14

Thanks for the assistance, and the advice (probably well deserved). I have it working goodly now.
Tofer
 
Posts: 3
Joined: 18. March 2019 16:24
XAMPP version: 7.3.1
Operating System: Mac OS Mojave 10.14.3


Return to XAMPP for Mac OS X

Who is online

Users browsing this forum: No registered users and 6 guests