dsmnedc798226 2017-03-30 06:53
浏览 70
已采纳

将Web表单连接到MySQL数据库

Using a MySQL database, I add users to the database like this test data:

INSERT INTO `database_users`.`Members` (`ID`, `Username`, `Password`,
 `First Name`, `Last Name`, `Email Address`, `Telephone Number`,
 `Address Line 1`, `Address Line 2`, `Town/City`, `Postcode`,
 `Mailing-list`, `Terms`) VALUES (NULL, 'Test', '', '', '', '', '', '',
 NULL, '', '', NULL, '');"

My HTML form looks like this:

<input type="submit" value="Join!">
    <div class="col-lg-6">
        <input type="text" placeholder="Town/City" id="Town/City">
    </div>
    <div class="col-lg-6">
        <input type="text" placeholder="Postcode" id="Postcode">
    </div>
</input>

I am looking to submit the form on my website and have the data upload to my MySQL database. Can anyone advise on what I am missing from my form?

  • 写回答

1条回答 默认 最新

  • doutang3760 2017-03-30 07:35
    关注

    Your sql query seems to be good, but if you don't know how to use PHP you'll be blocked often.

    The best thing to do is learn basic PHP to know how to implemant youself your register page, and ask on stackoverflow if you have an issue during the development.

    http://www.learn-php.org/

    And your form isn't correct: You need a <form> input and define on it the method (post or get), and the action (the file where the datas goes).

    Basically, your code have to be like:

    HTML (form.html)

    <form method="POST" action="save.php">
        <input type="text" name="pseudo">
        <input type="submit">
    </form>
    

    PHP (save.php)

    <?php
        if(isset($_POST['pseudo'])){ // Test if the variable exists
            $pseudo = $_POST['pseudo'];
            // Your SQL query here which save the pseudo. Don't forget to test your variables.
        }
        else {
            echo "pseudo is required";
        }
    ?>
    

    Don't forget to escape your variables and use prepared statements. Else, your site will be many flaws like XSS or SQL injections.

    Some links

    A prepared statement with Mysqli

    http://php.net/manual/en/mysqli.quickstart.prepared-statements.php

    Prevent XSS attacks

    https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet

    What is a SQL injection?

    http://php.net/manual/en/security.database.sql-injection.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器