This code is from w3schools which displays the email address and name once the user submits the form. However when I tried copying the code it wouldn't let me display the same output and would only say Cannot POST /welcome.php or it would display the welcome.php code whenever i submit.
I didn't even alter it in anyway but why wont it work? D:
index.html
<!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>
welcome.php
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
Related
Consider following html page:
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>
If GET is used for reading the data let's say "name" then following is understandable:
welcome.php
<html>
<body>
Welcome <?php echo $_GET["name"]; ?><br>
Your email address is: <?php echo $_GET["email"]; ?>
</body>
</html>
When POST is meant for writing the data How is it possible to read the "name" using POST? Why should the following work?
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
First of all add a name in your submit input <input name="submit" type="submit">
Second into welcome.php add if(isset($_GET["submit"])){ $submit = preg_replace('#[^a-z0-9]#i', '', $_GET['submit']); }
and then use Welcome <?php echo $submit; ?>
i suggest to use preg_replace if you want to pass values from page to page
I've just started using PHP forms for my website prototype, and it wasn't working so I decided to try to make a basic form example. No fancy CSS, just pure data. This is the code.
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>
welcome.php
<html>
<body>
Welcome <?php echo $_POST["name"]; ?>
<br />
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
The code works as far as displaying the 'Welcome ___ Your email address is: ____.
It just doesn't display the data entered in the form. For clarification as to whether my PHP works, I have tried just displaying some text and it worked fine. I use the PHP Editor phpDesigner8.
Thanks!
I've just got into php recently, and now i am working on a login form which has a signup page and a signup script to do all the database and such. But my $_POST is not working at all. I`ve tried searching online, confirm that my xampp/php/php.ini setting enable post process, and such. But all i get is nothing. To make the problem simpler i used a post tutorial code online
Posttest.php
<!DOCTYPE HTML>
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" id="name" name="name"><br>
E-mail: <input type="text" id="email" name="email"><br>
Submit
</form>
</body>
</html>
welcome.php
<html>
<body>
<?php
$disname="";
$disname = isset($_POST['name']) ? $_POST['name'] : '';
echo "$disname is your username";
var_dump($_POST);
?>
</body>
</html>
and the result is empty. Please help i`ve been working on this problem for few days.
Everything looks fine but the submit href link, which you should replace with a Submit input type:
Submit
to:
<input type="submit">
You can't use "a" tag for submit. "a" tag just direct to address. So you should use this:
<input type = "submit" value = "Submit">
<!DOCTYPE HTML>
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" id="name" name="name"><br>
E-mail: <input type="text" id="email" name="email"><br>
<input type = "submit" value = "Submit">
</form>
</body>
</html>
///////////////////////////////////////////////////////
//////welcome.php
<html>
<body>
<?php
$disname="";
$disname = isset($_POST['name']) ? $_POST['name'] : '';
echo "$disname is your username";
var_dump($_POST);
?>
</body>
</html>
Here i entered name nd email id but when i click on submit button my entered information is blank like below image.
In PHP clicking on the submit button doesn't print the information. I used $GET and $POST, both are not working.
<!DOCTYPE HTML>
<html>
<body>
<form action="php_forms.php" method="post">
Name: <input type="text" name="name"><br>
Email: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
It should be work.Change your action (php_forms.php) file code.I have tried in my server.Hope it will be helped.
<html>
<body>
Welcome <?php echo htmlspecialchars($_POST["name"]); ?><br>
Your email address is: <?php echo htmlspecialchars($_POST["email"]); ?>
</body>
</html>
Read More dealing with html forms in PHP.NET.
Your form uses get method and php_forms.php uses post method. Try
<form action="php_forms.php" method="post">
I have a form on my homepage and when it is submitted, it takes users to another page on my site. I want to pass the form data entered to the next page, with something like:
<?php echo $email; ?>
Where $email is the email address the user entered into the form. How exactly do I accomplish this?
The best way to accomplish that is to use POST which is a method of Hypertext Transfer Protocol https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
index.php
<html>
<body>
<form action="site2.php" method="post">
Name: <input type="text" name="name">
Email: <input type="text" name="email">
<input type="submit">
</form>
</body>
</html>
site2.php
<html>
<body>
Hello <?php echo $_POST["name"]; ?>!<br>
Your mail is <?php echo $_POST["mail"]; ?>.
</body>
</html>
output
Hello "name" !
Your email is "whatyou#addedonindex.com" .