Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass form data to another page with php

Tags:

forms

php

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?

like image 445
user1543782 Avatar asked Mar 06 '13 00:03

user1543782


People also ask

How do I display data from one page to another in HTML?

For sending data to two servelets make one button as a submit and the other as button. On first button send action in your form tag as normal, but on the other button call a JavaScript function here you have to submit a form with same field but to different servelets then write another form tag after first close.

What method is used to transmit data from forms to PHP?

PHP - A Simple HTML Form When the user fills out the form above and clicks the submit button, the form data is sent for processing to a PHP file named "welcome.php". The form data is sent with the HTTP POST method.

How can I pass HTML in PHP?

You can't pass data directly html to php. You have to call ajax get/post request from html to php. then php return calculated data to your ajax success method. after you can print your calculated data inside html.


1 Answers

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 "[email protected]" .

like image 95
Stepo Avatar answered Nov 10 '22 01:11

Stepo