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

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

报告相同问题?

悬赏问题

  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?