Pass form data to another page with php

前端 未结 1 1794
借酒劲吻你
借酒劲吻你 2020-12-03 14:57

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:

相关标签:
1条回答
  • 2020-12-03 15:50

    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" .

    0 讨论(0)
提交回复
热议问题