Jump to content

Error


SpOrTsDuDe.Reese

Recommended Posts

Hello. I just recently downloaded WAMP from www.wampserver.com. or something like that.I wanted a test to see if I could actually write PHP codes now. So I made a file called PHPtest.php and saved it in a file devoted to my creation of websites.This is the code I used: very basic

<!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" xml:lang="en" lang="en">	<head>	</head><body> <?phpecho "Simple PHP test blah blah";?></body>	</html>

Though strangely enough, I tried viewing this in the following browsers and got screwed:Opera (I JUST downloaded it about 4 minutes ago so I got the newest version (For my PHP + CSS + HTML + JS tests)IE 6 (Showed a download box for PHPtest.php)Mozilla FF (Showed a download box for PHPtest.php)Any ideas what's going on? Does my WAMP need a localhost or work with PHPmyAdmin or something? I'm totally befuzzled. Help...?

Link to comment
Share on other sites

No I'm not. If you want to run PHP in a web browser you need to run it through a web server. The web browser doesn't understand PHP code. If you want to run it from a command line you can open a command prompt and run php.exe with the name of the script you want to run, e.g. "php.exe -f c:\php\script.php". You can get a list of command line options on this page:http://www.php.net/manual/en/features.commandline.phpWhen running on the command line certain things aren't available, like $_POST, $_COOKIE, etc, those variables don't make sense when you're not running in a web server environment. The command line also changes a few configuration options, like it disables HTML error messages and shows them as plain text instead. You should read the page I linked to if you want to write command line scripts, there are several other differences.But it seems a little silly to install a web server if you're just going to run PHP on the command line. I'm not sure if you realize this, but your computer does not need to be online to run a web server, those aren't the same thing. But, if you want to run web PHP scripts, you do need to go through the server, regardless of whether or not your computer has a web connection at the moment. Click on this link and see what happens:http://localhost/http://127.0.0.1/

Link to comment
Share on other sites

First of all, that is 2 links, and you're not answering my question:I can't get PHP working because it opens as a file download.Simple answer please.You are explaining it so complicated. Talk like a hick or VERY explanatory. Here is stuff you might need to knowThe file for my PHPtest.php is...C:\Documents and Settings\Brandon\Desktop\RYAN HTML\Plooth Work\PHPtest.phpWAMP5 is installed. No settings have been changed. I have internet.See what you can do

Link to comment
Share on other sites

Good god man. Have you read the documentation for WAMP to see how to access the server? Open a browser.Type "http://localhost/" into the address bar.Notice you see some sort of Apache or WAMP page.The page is hosted on the web server that your computer is running, that WAMP installed.You need to put your PHP files into the same folder where the file is that you see in the browser.Check the WAMP documentation to figure out where that folder is. I've never installed WAMP so I don't know where it puts it.Put your PHP file in the same folder, and type the filename into the address bar in your browser.Unless WAMP set the web root to be your desktop, you're not going to be able to run PHP files from your desktop. They need to go in the web server root folder, wherever that happens to be on your computer. Regardless, you can't run PHP files by double-clicking on them anyway. Double-click on an HTML file and look at the address bar. See how it starts with "file://"? That means it's not going through the web server, the browser just opened the local file. Doing so will not execute PHP code.I'm sorry, I don't know how to make it any more clear.

Link to comment
Share on other sites

And also, (i would add this in but your reading this justsomeguy. I uplaoded it on my online website and i got this errorParse error: syntax error, unexpected T_ECHO in /home/gameyinc/public_html/PHPtest.php on line 105

Link to comment
Share on other sites

There were alot of semicolons. I got it working and it works great. However back to the problem at hand. I get everything you said except the part about saving your file in the folder on the local host site. I saw this (locations)

Your aliasesWarning: opendir(c:/wamp/apache2/conf/alias/) [function.opendir]: failed to open dir: No error in C:\wamp\www\index.php on line 214Warning: readdir(): supplied argument is not a valid Directory resource in C:\wamp\www\index.php on line 217Warning: closedir(): supplied argument is not a valid Directory resource in C:\wamp\www\index.php on line 224No Alias yet.To create a new one, use the WAMP5 menu.
Which one do i save it in. i saved my file in alot of places but dunno where.
Link to comment
Share on other sites

Save your files in the www folder (e.g. C:\wamp\www\PHPtest.php). Then you can access them e.g. http://localhost/PHPtest.phpYou don't need to be online to access the localhost, after all its local, innit? :)

Link to comment
Share on other sites

Did you go to http://localhost/PHPtest.php (like that)? Hmm... you can also try http://127.0.0.1/PHPtest.php . That may work. Remember you also still have to have WAMP running, even if it is offline (padlocked icon in task tray).

Link to comment
Share on other sites

Yes I did the localhost URL. Why would you use the 2nd URL you placed in the response? Would I change that to my own IP or just type yours? Is there a way to change the root directory of my wamp to my desktop? Gah this is so gay it isn't WORKINGGGGG. PHP hates me. I've had so much trouble with it...<!---For my online testing; how do i get my file to be like...

have those bolded parts. I tried saving my PHPtest.php as:PHPtest.php?hathisisatestkbut when I tried to go to the URL it's supposed to be saved as: www.gameyin.com/PHPtest.php?hathisisatestk(Thats not real URL. Example. Real PHPtest page is. http://www.gameyin.com/phptest.php)-->
Link to comment
Share on other sites

The IP 127.0.0.1 is a loopback IP, it always points to the current machine. The name localhost essentially resolves to the IP 127.0.0.1 (that's why I posted both of those links earlier). You can also use your own local IP, or you can use your computer name. My computer at home that has my server on it is called BLANKA, so I can type in http://blanka/ to access it on my local network.Apache is also case-sensitive, so make sure you type in the filename the exact same way you save it, capitals matter with Apache. For your other question, in this link:http://w3schools.invisionzone.com/index.php?showtopic=16965The filename is not "index.php?showtopic=16965", it is just index.php. Everything that comes after the question mark is the querystring, and the PHP script can access those variables using the $_GET array.

Link to comment
Share on other sites

Is there a way to change the root directory of my wamp to my desktop?
Yes. Go into your wamp\Apache2\conf folder and find a file called httpd.conf. Go to around line 150, and you should see the DocumentRoot directive. You can change that to wherever you want.
Link to comment
Share on other sites

Ok, I'll go check out some querystrings in PHP. New to it so yea...I'll go do that changing directory to my desktop and see if anything changes. Thanks~BTW: Whoever can give me the winning advice on how to get PHP working gets a prize :)

Link to comment
Share on other sites

Ok basically I figured it out. With the localhost, I forgot to load up WAMP because I thought it was already up. I started up WAMP and typed in http://localhost/PHPtest.phpNote: I knew about the Apache being CaSe SeNsItIvE

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...