PHP not working

Problems with the Windows version of XAMPP, questions, comments, and anything related.

PHP not working

Postby pvtryan » 15. July 2010 23:43

PHP isn't working on my localhost XAMPP server. I tried completely reinstalling XAMPP, leaving all options at default, and I still can't get even an "echo." I tried restarting Apache, and uninstalling/reinstalling the Apache service. I tried turning off the firewall. Nothing has worked. The code is fine, because when I uploaded it to my remote server the page worked perfectly.

Code in case it's wanted (note that it is HTML5):

<!--Main Template-->
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<title>Title</title>
<link rel="stylesheet" type="text/css" href="css/main.css" />
<script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>

<div id="container">
<div id="header">

</div>
<div id="navbar">


</div>
<div id="sidebar">

</div>
<div id="content">
<?php echo "test"; ?>
</div>
<div id="footer">

</div>
</div>
</body>
</html>
pvtryan
 
Posts: 16
Joined: 10. April 2010 21:57

Re: PHP not working

Postby Altrea » 16. July 2010 04:41

Your code looks fine.

What file-extension do you have given this file?
How do you open the file in your Browser (Whats standing in the browser location bar)?
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: 11933
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: PHP not working

Postby pvtryan » 16. July 2010 04:51

I gave it .php of course. And I open the file in my browser in 2 ways: by using my text editor's "preview in browser" function, and by opening the directory of the file and dragging the file into my browser.
pvtryan
 
Posts: 16
Joined: 10. April 2010 21:57

Re: PHP not working

Postby Altrea » 16. July 2010 05:24

pvtryan wrote:by using my text editor's "preview in browser" function

What Editor do you use?
Maybe you had to do some configurations in your editor for the right use with the xampp package

pvtryan wrote:and by opening the directory of the file and dragging the file into my browser.

This will never run. PHP is a server-side script language. Your Browser don't parse PHP-Code! You had to request this script on your webserver with the http protocol.

Try this:

If this is your file-path:
Code: Select all
C:\xampp\htdocs\projectxyz\test.php

Type in your browser http://localhost/projectxyz/test.php
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: 11933
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: PHP not working

Postby pvtryan » 16. July 2010 05:43

I'm using Notepad++ right now. And I typed the path to the file in my address bar and it still didn't work.
pvtryan
 
Posts: 16
Joined: 10. April 2010 21:57

Re: PHP not working

Postby Altrea » 16. July 2010 06:34

pvtryan wrote:it still didn't work.

This is no error reporting which assists me to help you.

What doesn't work?
What do you see?
What happened and what doesn't happen?

pvtryan wrote:I'm using Notepad++ right now.

The "launch in Browser XY" function from Notepad++ just opens the file locally and doesn't send requests to any existing webservers. So thats the same as type in your Browser C:\path_to_file\file.xyz, which will not run, too.

pvtryan wrote:And I typed the path to the file in my address bar and it still didn't work.

What path do you post in your Address bar? Just copy and paste it here, can't be that difficult...
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: 11933
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: PHP not working

Postby pvtryan » 16. July 2010 07:10

Altrea wrote:What doesn't work?
What do you see?
What happened and what doesn't happen?

The PHP in my page doesn't work.
I see my page without the "echo."
What happened is that the page loaded like an html file and ignored the php echo.

Altrea wrote:What path do you post in your Address bar? Just copy and paste it here, can't be that difficult...


http://localhost/xampp/mysite/main.php
pvtryan
 
Posts: 16
Joined: 10. April 2010 21:57

Re: PHP not working

Postby Altrea » 16. July 2010 10:10

pvtryan wrote:The PHP in my page doesn't work.
I see my page without the "echo."


relating to your sourcecode in your first post, you just see a white page?
If you open the sourcecode view in the browser, do you see your HTML5 structure?

pvtryan wrote:http://localhost/xampp/mysite/main.php

looks fine. its recommend to create your own pages outside of the htdocs/xampp folder (e.g. xampp/htdocs/mysite/main.php instead of xampp/htdocs/xampp/mysite/main.php).
I have tested your example (code + folder structure). On my Testsystem all is running fine (XAMPP 1.7.3 on Windows XP).

So, i don't know, whats the problem with your installation.
- you don't use short_open_tags
- you don't try to use php syntax in other file-extensions as .php
- You don't try to access the file locally in your browser without webserver (you use http://localhost/...)

Do you have changed something in the configs?

Maybe a clean new install of xampp is the only way to get rid of this. I really don't know. Maybe someone else knows!?
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: 11933
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: PHP not working

Postby pvtryan » 16. July 2010 16:12

I said that I did a clean install already! And sorry, I accidentally put xampp in there, I do have my own folder, so it would be located at http://localhost/mysite/main.php.
pvtryan
 
Posts: 16
Joined: 10. April 2010 21:57

Re: PHP not working

Postby wonglitheng » 18. July 2010 10:11

Hello, I'm self=learning PHP. Can anyone point out the error that I did in the codes below?
I keep getting "Parse error: syntax error, unexpected T_ECHO in D:\xampp\htdocs\5_12.php on line 16"
And my Line 16 is: "echo "<td>";"

<html>
<head>
<title>Listing 5.12 Nesting Loops </title>
</head>

<body>

<?php
echo "<table border=\"1\"> ";
//$y=1;
for ($y=1; $y<=10; $y++)
{
echo "<tr>";
for ($x=1; $x<=10; $x++)
(
echo "<td>"; <---------Line 16
echo ($x*$y);
echo "</td>";
)
echo "</tr>";
}
echo "</table>";
?>
</body>

</html>
Man's mind, once stretched by a new idea, never regains its original dimensions.
~by: Oliver Wendell Holmes
wonglitheng
 
Posts: 1
Joined: 18. July 2010 10:06

Re: PHP not working

Postby Altrea » 18. July 2010 11:18

wonglitheng wrote:Hello, I'm self=learning PHP. Can anyone point out the error that I did in the codes below?
I keep getting "Parse error: syntax error, unexpected T_ECHO in D:\xampp\htdocs\5_12.php on line 16"
And my Line 16 is: "echo "<td>";"

<html>
<head>
<title>Listing 5.12 Nesting Loops </title>
</head>

<body>

<?php
echo "<table border=\"1\"> ";
//$y=1;
for ($y=1; $y<=10; $y++)
{
echo "<tr>";
for ($x=1; $x<=10; $x++)
(
echo "<td>"; <---------Line 16
echo ($x*$y);
echo "</td>";
)
echo "</tr>";
}
echo "</table>";
?>
</body>

</html>


Wrong Bracket in lines 15/19!
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: 11933
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: PHP not working

Postby pvtryan » 19. July 2010 16:36

wonglitheng, I suggest developphp.com for your php problems in the future. Those guys are great.
pvtryan
 
Posts: 16
Joined: 10. April 2010 21:57


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 234 guests