Page 1 of 1

PHP not working

PostPosted: 15. July 2010 23:43
by pvtryan
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>

Re: PHP not working

PostPosted: 16. July 2010 04:41
by Altrea
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)?

Re: PHP not working

PostPosted: 16. July 2010 04:51
by pvtryan
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.

Re: PHP not working

PostPosted: 16. July 2010 05:24
by Altrea
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

Re: PHP not working

PostPosted: 16. July 2010 05:43
by pvtryan
I'm using Notepad++ right now. And I typed the path to the file in my address bar and it still didn't work.

Re: PHP not working

PostPosted: 16. July 2010 06:34
by Altrea
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...

Re: PHP not working

PostPosted: 16. July 2010 07:10
by pvtryan
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

Re: PHP not working

PostPosted: 16. July 2010 10:10
by Altrea
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!?

Re: PHP not working

PostPosted: 16. July 2010 16:12
by pvtryan
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.

Re: PHP not working

PostPosted: 18. July 2010 10:11
by wonglitheng
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>

Re: PHP not working

PostPosted: 18. July 2010 11:18
by Altrea
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!

Re: PHP not working

PostPosted: 19. July 2010 16:36
by pvtryan
wonglitheng, I suggest developphp.com for your php problems in the future. Those guys are great.