PHP problem

Discuss how to write good code, break bad code, your current pet projects, or the best way to approach novel problems

PHP problem

Post by BlackSundayHacker on Tue Jul 24, 2012 3:02 pm
([msg=68274]see PHP problem[/msg])

Hi guys,
A few days ago I started to learn PHP, I set up a XAMPP test server and I have a problem... When I try to print PHP text it doesn't show anything, the page is blank... I searched everywhere but I cant find solution for this problem :cry:
Here are some samples:
Code: Select all
<html>
   <head>
      <title></title>
   </head>
   <body>
      <h1>Test!</h1>
   <?php
      print("Hi!");
   ?>    
</body>
</html>

This shows only: Test!
Another sample:
Code: Select all
      <?php
         print("<h1>Test</h1>");
      ?>

Result: Test"); ?>

Any help wold be greatly appreciated, BlackSundayHacker.
BlackSundayHacker
New User
New User
 
Posts: 2
Joined: Tue Jul 24, 2012 2:42 pm
Blog: View Blog (0)


Re: PHP problem

Post by mShred on Tue Jul 24, 2012 5:07 pm
([msg=68279]see Re: PHP problem[/msg])

Copied and pasted your code, it works on my own server. That said, I would use echo() rather than print() for something this simple. But in regards to your situation, your setup must have something wrong with it. Your PHP must not be working. How do you have it set up?
Image

For those about to rock.
User avatar
mShred
Administrator
Administrator
 
Posts: 1766
Joined: Tue Jun 22, 2010 4:22 pm
Blog: View Blog (2)


Re: PHP problem

Post by LoGiCaL__ on Tue Jul 24, 2012 6:57 pm
([msg=68285]see Re: PHP problem[/msg])

Same here, code ran fine.

Does your files have a .php extension?

-- Tue Jul 24, 2012 7:16 pm --

That looks to be your problem if everything is setup on the server correctly. Rename your files with a .php extension instead of a .html. I was able to duplicate both results by having a .html extension with your supplied code.
User avatar
LoGiCaL__
Addict
Addict
 
Posts: 1063
Joined: Sun May 30, 2010 12:33 pm
Blog: View Blog (0)


Re: PHP problem

Post by BlackSundayHacker on Thu Jul 26, 2012 11:01 am
([msg=68333]see Re: PHP problem[/msg])

I found my problem, everything was ok, just I was opening my page from HDD not localhost. :)
Thanks for the help anyway.
BlackSundayHacker
New User
New User
 
Posts: 2
Joined: Tue Jul 24, 2012 2:42 pm
Blog: View Blog (0)


Re: PHP problem

Post by mShred on Thu Jul 26, 2012 4:09 pm
([msg=68344]see Re: PHP problem[/msg])

Ah, makes sense. You have to route through apache for the PHP script to be recognized.
Topic = SOLVED
Image

For those about to rock.
User avatar
mShred
Administrator
Administrator
 
Posts: 1766
Joined: Tue Jun 22, 2010 4:22 pm
Blog: View Blog (2)



Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests