I have this two files:
index.html
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
And welcome.php
<html>
<body>
Welcome, <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
This is example from there
When the user fills the form and hits "enter" it should display:
Welcome, the_name_you_enter
Your email address is address_you_enter
But for me it only displays welcome.php source code (I am using Safari 7).
Does anyone knows why?
It sounds like your calling up the page from a server that is not executing php.
This usually happens because the PHP file is not executed on a web server or PHP is not enabled on your webserver.
You are probably trying to access the file directly using file://
Take a look at MAMP (I am assuming you are using OS X)
Related
I have tried plenty of methods already including ones on this site. The echo function works for the words on the .php file but it just ignores the form information. Please could someone tell me where I am going wrong. I am using Google Chrome if that matters.
This is the .html file.
<!DOCTYPE HTML>
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
and this is the .php file named welcome.php
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
and all it displays after entering information and clicking submit, all it displays is:
Welcome
Your email address is:
I would be very grateful if anyone can help. Thanks in advance.
Say the page name, containing the form, is index.html.
Put both the files in your "www/your_project" folder.
Type in browser's address bar http://localhost/your_project
Provide some input in the form on index.html and hit Submit Query button.
You will see your $_POST data on welcome.php
I have two files, testpage.html and testpage.php in the same folder.
This is testpage.html
<!DOCTYPE HTML>
<html>
<body>
<form action="testpage.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
This is testpage.php
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?><br>
</body>
</html>
The form seems to work okay but when I hit submit nothing shows up on the next page. no matter what I enter int he form, it always reads "Welcome" "Your email address is:" with nothing entered after that like its supposed to.
Do I have something configured incorrectly? Am I using the wrong browser (firefox)?
Thanks!
"I am accessing it via file:///C:/... should I be accessing it some other way instead?"
Just as I thought.
There you go. A web browser will not parse PHP directives that way.
It must be accessed as http://localhost/yourfile.xxx
Plus, a webserver and PHP need to be installed in order to parse PHP directives.
"I don't think I have Xampp or any virtual server set up... I'll look into that, any tips on where to start?"
You need to install one. Here are a few links to get you started and depending on the platform you are using.
https://www.apachefriends.org/
http://www.wampserver.com/
https://www.mamp.info
http://www.easyphp.org/
Pick your flavour.
I am starting with PHP and read this page from w3schools:
http://www.w3schools.com/php/php_forms.asp
There is a code example to enter your name and e-mail and below it there is another code example that can echo the inputs of the form. The problem is that my inputs are not displayed on the second page.
The code of the form:
<!DOCTYPE HTML>
<html>
<body>
<form action='welcome.php' method='post'>
Name: <input type='text' name='name'><br>
E-mail: <input type='text' name='email'><br>
<input type='submit'>
</form>
</body>
</html>
The code of the output page (welcome.php):
<html>
<body>
Welcome <?php echo $_POST['name']; ?><br>
Your email address is: <?php echo $_POST['email']; ?>
</body>
</html>
Why are my inputs not displayed on the welcome page? Thank you for your help
11.02.2015
I have xampp and it should run fine
I also put my sourcefile in the correct folder htdocs
I followed this tutorial (its German sorry :( )
http://www.php-einfach.de/php-tutorial/php-erste-schritte.php
Do you know what am I missing?
you can't open PHP by double-click it like you are opening HTML files, it can't run on c:\ you should access it like http://localhost/test2/welcome.php
and you need PHP interpreter too.
Our university provides a public folder to every student where we put out html files and host our own website.
My question is:
Am I able to do some server-side programming in this situation? I found this example from w3school:
client-side:
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
server-side:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
I put both files under the folder, but nothing works. I am sorry that this might be a stupid question. But I would really like to find out what is happening.
Thank you guys so very much in advance!
The host space they provide may not have enabled PHP for you to use
I'm very new to php/html, and I'm trying to teach myself the basics of creating and processing an html form.
I created a folder called Website. In it I created an html file index.html. I also created a file submit.php.
(this code is taken from: http://www.w3schools.com/php/php_forms.asp)
In index.html I have:
<html>
<body>
<form action="submit.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
In submit.php I have:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
When I open the html file in chrome and fill in the blanks and press submit, I get redirected to a page with the code in submit.php:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
I should be getting this output:
Welcome Hannah
Your email address is Hannah#example.com
What am I doing wrong that the output isn't working?
Thanks!
PHP is processed on a server, so you can't treat it like HTML, it needs to be placed on a server that has apache installed. You can install one on your computer, using something like the following:
WAMP
LAMP
MAMP
XAMPP
Sounds like you are doing this via files on your desktop and not via a web server. Either on the Internet or via your local machine. I took your example 100% as presented, placed it within my htdocs folder in MAMP (LAMP for the Macintosh) and it behaves 100% as expected.
The difference between loading files on your desktop versus a web server is a web server will process the PHP. If you just do it as files, then the file gets loaded & doesn’t get parsed.