weixin_33701294 2019-11-27 09:09 采纳率: 0%
浏览 47

如何从html访问php?

I am sorry if this is a repeating question, but I can't find anyone who might have the same question as me yet. I am new in html and php, and I am trying to learn more by practising, basically creating a registration form and keep all the data in the MySQL database, by using xampp. I have created a registration form and saved it as a .html file format, but how can I use php to send the user input from html to the MySQL database? I have seen a lot of examples on Google, but most of them are using php file format, for example instead of registration.html, they use registration.php. I really do appreciate your help. Thank you very much StackOverflow community members.

P/S: I use Visual Studio Code to do this

  • 写回答

2条回答 默认 最新

  • weixin_33736048 2019-11-27 09:21
    关注

    Step 1: write this code in your html file

    in form action redirect it to the php file

    <!DOCTYPE html>
    <html>
    <head>
        <title>form</title>
    </head>
    <body>
        <form method="post" action="st.php">
            <input type="text" name="text">
            <input type="submit" name="submit_btn">
        </form>
    </body>
    </html>
    

    Step 2 create st.php file and call the action

    <?php
        if(isset($_POST['submit_btn'])){
            //your code
           header('Location:yourHTMLFile.html?status=success');//redirect to your html with status
        }
    ?>
    
    评论

报告相同问题?