I'm new to PHP and I'm following the PHP tut on w3schools. I am using Eclipse's latest IDE version (3.6 I think). for my script helloDriver.php it functions fine when ran as a php script. it doesn't on my html file especially when I use a similar method to the example from w3schools:
http://www.w3schools.com/PHP/php_forms.asp
This would be my code for helloDriver.php:
<html>
<body>
go
<?php
echo "giga";
?>
power rangers
</body>
</html>
This is my code for homepage.html
<html>
<body>
Hey
<form action="helloDriver.php">
<input type="submit />
</body>
</html>
"Hey" and "go" both display so I know that the php file is being called but I don't know why the echo command doesn't.
Even before this I copied line by line with what the w3schools example was with the exception of welcome.php since that is helloDriver.php
How I access the html file is double clicking it since Eclipse doesn't have any options to run the program. Any ideas what I am doing wrong?
Where are these files hosted? I'm guessing your web server (e.g., Apache or IIS) isn't configured to run .php files through the PHP interpreter, but instead is serving them statically.
I'm having a really hard time working out what your question is.
Some problems with your HTML file are:
You're missing the closing </form> tag
You haven't closed the quotes on your submit button.
The complete markup should probably be more like
<form action="helloDriver.php">
<input type="submit" />
</form>
Another thing that might be the problem, you need to access the PHP scripts through a web server. Have you installed something like XAMPP?
I ended up figuring it out. Thank you guys for help and thanks for suggesting XAMPP.
Installed it from this link (googling XAMPP works just as well):
http://www.apachefriends.org/en/xampp-windows.html#1173
It was straightforward and easy to set up. Set the destination to install on the C: drive. Also stumbled across this tut vid on how to set up a PHP project using PHP, XAMPP, and Eclipse:
http://www.youtube.com/watch?v=hfHEmZXJLgw
I should be able to figure things through trial and error. Thanks again!
Related
I'm currently beginning with PHP and I wanted to get started with a mini-project for some hands-on experience. Here's the code that I began with:
<html>
<header>
<title>Test</title>
</header>
<body>
<h3>Some example title</h3>
<?php
$randomNumber = rand(1000,9000);
print "Here's a random number: {$randomNumber}.";
?>
<p>Some more text.</p>
</body>
</html>
However, when I saved it as index.php and previewed it on Google Chrome, the PHP part doesn't show up. Can anyone help me realize what I'm doing wrong?
Thanks!
To run PHP code (server side) you need a server, or a 'server-emulator' some of the most commonly used are:
XAMPP
WAMP
Unlike the html in your .php files, the php code must be processed by a server and returned to the browser. I've tested your code with a server and it works like a charm.
After installing one of the above "emulators" you need to (this is a simplified tutorial, check a real tutorial):
place your .php files in the public_html or htdocs folders that are
created in the emulator's folder in your computer.
Turn on your server
go to localhost/your-file-path/index.php
If you only need to test soft code (like what's on yout example) and not develop whole projects use IDONE
PHP is used in the server side, so, you need to install an environment (Apache, PHP) to interpret the PHP. If you use Mac or Windows, you can install Mamp. For unix, you need to install some packages, i'll invite you to see this tutorial: Lamp tutorial.
I am a beginner in PHP and I am trying to embed PHP in HTML as that is how I am going to need it in my project. This one is a very simple code saved as Trial.html
<html>
<head>
<title>Trial Page</title>
</head>
<body>
Hello, today is <?php echo "a great day!"; ?>.
</body>
</html>
When I load this page from server (I am running Apache Tomcat 7 locally), Only the HTML part is getting displayed and the PHP part is not. What am I missing? Do I need to include anything else or am I taking a completely wrong approach for this?
Rename "Trial.html" to "Trial.php" this is essential when you try to run php code.
You should save your file as .php and run it on a server with php installed on it.
check XAMP to install a local server
EDIT
Just saw that you're running Tomcat, just make sure php is installed, that your server is running, you're running your file from the server And your file is save as .php
You change file name from trial.html to trial.php
i have a rather simple .PHP file with the following code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>hello world</p>
<?php echo "test";
?>
</body>
</html>
yet when i run it all i see is "hello world", i checked firebug and it showed me this
and in chrome it simply comments the php out
am i missing something important here?
PHP is an pre-processed, interpreted language which means a web server (like apache) with the PHP interpreter installed must serve it to you. You must install a webserver on your local machine and access it via a URL like http://localhost. PHP cannot be viewed the same way as locally-served HTML files (like what happens when you double click them) through the file:// prototcol.
But never fear, it is not hard to get a webserver installed. Try something like XAMPP, which will install Apache, PHP, and MySQL for you and give you a nifty little control panel.
You seem to be missing PHP. Where is the file located? Are you trying this in a server?
If you are new to PHP I recommend you using WAMP or LAMP, it's the easiest way to start using the languague.
A quote from here PHP gets commented out by the browser
Browsers shouldn't comment out PHP, they shouldn't even see PHP.
Most likely, what you are experiencing is that the <? is not being
parsed by the PHP engine and being delivered to the browser. The
browser is then treating it as an unknown tag and ignoring it.
The solutions are:
Don't use short tags as they are not turned on for all PHP installations. If you have > <? some code change it to <?php some code
2.Make sure you are trying to run your PHP on a server that supports PHP.
Try installing XAAMP, It will install everything you need for PHP Development.
Oh! I think you're saving it as .PHP with capital letters, Don't use capital letters, Use small letters, so your file name should look something like test.php.
I've already tried the advice given on this page, by opening my .php page with Chrome, Mozilla, and IE (instead of dragging it to them), my EasyPHP is started (along with the other services I just installed with it), my files are located in C:\inetpub\wwwroot (on Vista), and so far, no PHP is being outputted. It either shows up as code on the page, or it doesn't work at all (includes don't work, for example). I tried configuring the DirectoryRoot in the httpd.config file (I commented out the original first, instead of deleting it), so it would point to the wwwroot directory, but that didn't work either. I am very new to EasyPHP and it's been a few years since I really dealt with regular PHP, Apache, and MySQL, so I'm grasping at straws here.
The code in my .htm file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head>
<title>MySite</title><link href="MySite.css" rel="stylesheet" type="text/css"></head>
<body>
<?php
include("topbar.php");
?>
<div id="content">
<h2>Content Goes Here</h2>
</div>
</body>
</html>
The code in my topbar.php file:
<?php
echo '<div id="container"><div id="header">';
echo '<h1>This is the header.</h1><p class="description">';
echo 'Usually some sort of tagline or description is placed here.</p></div>';
?>
I don't know. I've been searching all over the PHP main site, as well as a few random pages that came up when I used my search engine... I've gone through the EasyPHP FAQ page, and I haven't yet found an answer the would point me in the right direction. Other than attempting to edit the httpd.config file, I haven't gone through any other files created by EasyPHP, mainly because I wouldn't know which ones to try editing, nor which lines, or with what. I just installed EasyPHP last night. I'm glad for any assistance anyone can provide in plain English (please, no one try to show off how cool you are with all your fancy technobabble that I'd have to get out a tech dictionary for, or lengthy examples that would be hard for a newb to read, thanks).
Web server will not process PHP code written in file extension other than .php. Try changing file extension to .php instead of .html.
You can use HTML tags within .php file.
I have a quick question that I can't figure out. I've tried searching Google and following examples, but I can't find anything.
I have an HTML form that I'm trying to process with a PHP file, but when I submit the form, it merely prints the source of the PHP file, it doesn't execute it. If I run the PHP file by itself (not indirectly through the HTML button), it works fine.
HTML form header:
<form id="registrationform" name="registrationform" method="post" action="processregistration.php">
Submit button:
<button type="submit" value="Submit" >Create</button>
The PHP form is just <?php print "Hello"; /?
Again, it runs fine if I just run the PHP file, but prints the PHP file (doesn't run) when it gets called through the HTML form.
Any help is appreciated.
edit-Running locally through Coda
edit-Here is the output that I'm getting:
Output when the PHP is called through an HTML action:
</php
print "Hello";
?>
Output when I run the PHP directly through Coda:
Hello
I had the same problem and just fixed it on my coda version 1.7.4
I installed MAMP on my mac and set up the apache path under MAMP preferences to the folder where my sites are located;
/Users/yourUserName/Sites
this points MAMP's 'http://localhost:8888' address to your sites folder, if you paste that on your browser you'll now see your sites folder's content in the browser.
then, all you do is point the local site's connection settings to the site you are testing;
I was going to post an image, but I'm new to the site and wasn't allowed.
Under my site's preferences i set up the addresses as follows;
Root URL : 'http://localhost:8888/yourSiteRootFolder/'
Local URL : 'http://localhost:8888/yourSiteRootFolder/'
Remote Root : /yourSiteRootFolder/
Local Root : /Users/amartinez/Sites/yourSiteRootFolder/
I hope this is related to the problem you're having and helps you fix it.
Line #19 from Coda 1.6 Release notes:
Coda no longer tries to locally
preview a remote PHP file while
editing/previewing
Listed under "Improvement" - doubt they brought it back for the 1.7 release.
I'm running Apache2/PHP5 10.5.8 OS X (no problem reproducing your issue with Coda)
Even when running my form.html and post.php files from /Library/WebServer/Documents folder.
My sample files work fine in the Apache env....I just needed to run them through Coda to "break" them. :-)
Are you sure the html file and the php script are on a server with php support enabled?
I've never used Coda, but you need to be running it through a server (e.g. Apache + PHP). You cannot just open the file itself within Windows.
Try looking at xampp as a quick server for testing.
If it works properly, you should be viewing the PHP file on something like http://localhost/test.php instead of file:///something/test.php.
This may be because you don't have PHP installed on your server. I would check to make sure that your hosting package included PHP, pre installed.
Here are some resources to get you started with that, if not installed:
http://www.thesitewizard.com/php/install-php-5-apache-windows.shtml
http://www.php.net/manual/en/install.php
http://www.w3schools.com/PHP/php_install.asp
Edit: actually, I think I may have found it.
If you look at the starting PHP tag, you have a slash instead of a ?. If that's in your script, just change that to <?php. But it may not be, it could be that's just question format-ing.