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.
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 just started to learn HTML and PHP, but have run into a road block while following beginner tutorials. I am attempting to have the user input numbers into a form on the HTML page, then press submit to redirect to a PHP page that displays the values. The PHP page shows up and successfully displays prepared text but displays nothing for the values.
HTML code:
<html>
<body>
<head>
<title>Practice Page</title>
</head>
<h1>Numbers</h1>
<p>Put numbers in the boxes</p>
<form action="welcome.php" method="post">
NumOne: <input type="text" name="oynumone"><br>
NumTwo: <input type="text" name="oynumtwo"><br>
<input type="submit" value="Submit" id="SubmitRegister" name="submit" />
</form>
</body>
<html>
PHP code:
<html>
<body>
Number one is <?php echo $_POST["oynumone"]; ?><br>
Number two is <?php echo $_POST["oynumtwo"]; ?>
</body>
</html>
Both of the files are simply in the same folder in my documents. I understand that I need a server to host PHP content; I have downloaded MAMP for this, but I don't yet understand how to use it.
Any help would be most appreciated.
Store both file name with .php extension AND/OR update Welcome.php like below -
Welcome.php
<?php
if isset($_POST['submit'])
{
$oynumone = $_POST['oynumone'];
$oynumtwo = $_POST['oynumtwo'];
echo "Number one is ".$oynumone;
echo "Number two is ".$oynumtwo;
}
?>
Also check this
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.
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 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)