Not Recognising Php

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

Not Recognising Php

Postby ScratchBack » 16. June 2009 12:59

Can somebody help me out with getting started?

Php doesn't work for me, I've tried a simple HelloWorld.php script and I'm just getting a blank page in my browser.
The file is saved in the correct directory (file:///C:/xampp/htdocs/mystuffchris/helloWorld.php) as far as I know.
The code used is...
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
   <title>Hello World</title>
</head>

<body>
    <p><?php echo "Hello World"; ?></p>
</body>

</hmtl>


I've also tried using Php with a Html form with action="borderMaker.php". Here's borderMaker.php sourcecode...
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Your Output</title>
</head>
<body>
<h1>Your Output</h1>
<div style = "text-align: center">
<?php

//retrieve all the variables
$basicText = filter_input(INPUT_POST, "basicText");
$borderSize = filter_input(INPUT_POST, "borderSize");
$sizeType = filter_input(INPUT_POST, "sizeType");
$borderStyle = filter_input(INPUT_POST, "borderStyle");


$theStyle = <<<HERE
"border-width:$borderSize$sizeType;
border-style:$borderStyle;
border-color:green"
HERE;

print "<div style = $theStyle>";
print $basicText;
print "</div>";

?>
</div>

</body>
</html>


When I use the Html form and click the Submit button I just get text in the browser like this...

YOUR OUTPUT

";print $basicText;print "
"; ?>

The files are saved with the correct extensions. I have tried using Firefox and Internet Explorer, tried both Xampp and Wampserver, my browser just won't recognise the Php.

I know this is a log post for what I suspect is a real Noob problem but I'd be really greatful of any advice, thanks.
ScratchBack
 
Posts: 6
Joined: 14. June 2009 19:24

Re: Not Recognising Php

Postby Wiedmann » 16. June 2009 13:32

my browser just won't recognise the Php.

Your browser doesn't know anything about PHP.
--> You must open PHP files through the server with "http://...".
(see readme_en.txt)
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Not Recognising Php

Postby ScratchBack » 16. June 2009 15:59

Hey Thanks for the post,
Does this mean that if I have a html file with a form that references a php file, and the php file is in the same folder that
I cannot refer to the php file simply by typing...
<form method = "post"
action = "borderMaker.php">
in the html file?

That's what I have tried and it won't work.
Thanks.
ScratchBack
 
Posts: 6
Joined: 14. June 2009 19:24

Re: Not Recognising Php

Postby Wiedmann » 16. June 2009 16:06

Does this mean that

No, that does this not mean (that's the way like forms are working).
--> just open your files through the webserver and not with e.g. a double-click.
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Not Recognising Php

Postby newbie2244 » 16. June 2009 18:46

Greetings To Scratchback-

In addition to what Wiedmann said, also

Check on the differences between print() and echo() and related functions. For a short discussion about the differences between print() and echo(), see this FAQTs Knowledge Base Article: » http://www.faqts.com/knowledge_base/vie ... d/1/fid/40.

Perhaps this will help.

Regards-
newbie2244
 
Posts: 49
Joined: 20. February 2009 22:39

Re: Not Recognising Php

Postby newbie2244 » 16. June 2009 21:21

Greetings-

Did you write these scripts yourself or did you copy them from someplace? Look at what you wrote:

Code: Select all
</hmtl>
Is this correct?? --> Error in last line of your first file.
So why wouldn't your script work?

I realized after reading your code in total that although the link I previously provided has useful content . . . but it probably would not be helpful to you.

What are you actually trying to do with your second script?

Where are your inputs coming from?

Go to http://us.php.net/manual/en/function.print.php...Read carefully the message written by "user at example dot net" on 25-Aug-2008 04:47: (The previous supplied link gives you the same info but not as explicitly. ) This explains why you get the following:

Code: Select all
YOUR OUTPUT

";print $basicText;print "
"; ?>


Regarding your actual code for $theStyle, read carefully before you ask why it doesn't work
Code: Select all
$theStyle = <<<HERE
"border-width:$borderSize$sizeType;
border-style:$borderStyle;
border-color:green"
HERE;


Check the heredoc syntax and the function of double quotes. Look carefully at your punctuation. Anything missing?
http://us3.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc . . . See Example #2.

A good introduction to php can be found in the tutorial at http://w3schools.com/php/default.asp.
Work through all the examples yourself. (Copy or retype and run them). Then try making small changes.

Look at the effect of double quotes and single quotes on strings and variables using the print function. Look at the effect of double quotes and single quotes on strings and variables using the echo function.

Its important to start small and actually understand the constructs that you are using. Then you can build up.

Good Luck.

Regards-
newbie2244
 
Posts: 49
Joined: 20. February 2009 22:39

Re: Not Recognising Php

Postby ScratchBack » 17. June 2009 15:58

Hey Thanks for the help guys,

I got Php running on one of my PCs, my laptop which is using Wampserver, by following your advice (typing "http://localhost/helloworld.php" to run the file).
Although when I use the same method on my desktop, which is running XAMPP, the result is the browser shows...

-----------------------------------------------------------------------------
Object not found!

The requested URL was found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.

Error 404
localhost
06/17/09 15:04:15
Apache/2.2.9 (win32)/DAV/2 mod_ssl/2.2.9 OpenSSL/0.9.8h mod_autoindex_color PHP
/5.2.6
-----------------------------------------------------------------------------

I have feeling I'm getting closer, Thanks very much!
ScratchBack
 
Posts: 6
Joined: 14. June 2009 19:24

Re: Not Recognising Php

Postby Wiedmann » 17. June 2009 16:41

(typing "http://localhost/helloworld.php" to run the file) ... the result is the browser shows...
Code: Select all
Object not found!

There is no file "helloworld.php" in your "htdocs".
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Not Recognising Php

Postby ScratchBack » 18. June 2009 13:29

Thanks for the Pointers Wiedmann!!!

I had been typing the URL "http://localhost/helloworld.php" in the address bar, this wasn't working because I had my files stored
in a subfolder in the htdocs folder, so I got the Object not found error 404 message.
When I typed "http://localhost/mystuffchris/helloworld.php" that worked.

Now I can get down to some coding, thanks! :P
ScratchBack
 
Posts: 6
Joined: 14. June 2009 19:24


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 126 guests