• <bdo id='l2yeq'></bdo><ul id='l2yeq'></ul>

  • <legend id='l2yeq'><style id='l2yeq'><dir id='l2yeq'><q id='l2yeq'></q></dir></style></legend>
    <tfoot id='l2yeq'></tfoot>

      <small id='l2yeq'></small><noframes id='l2yeq'>

    1. <i id='l2yeq'><tr id='l2yeq'><dt id='l2yeq'><q id='l2yeq'><span id='l2yeq'><b id='l2yeq'><form id='l2yeq'><ins id='l2yeq'></ins><ul id='l2yeq'></ul><sub id='l2yeq'></sub></form><legend id='l2yeq'></legend><bdo id='l2yeq'><pre id='l2yeq'><center id='l2yeq'></center></pre></bdo></b><th id='l2yeq'></th></span></q></dt></tr></i><div id='l2yeq'><tfoot id='l2yeq'></tfoot><dl id='l2yeq'><fieldset id='l2yeq'></fieldset></dl></div>
      1. mysqli_query 通过变量输入

        时间:2023-10-11

        <i id='8NUVx'><tr id='8NUVx'><dt id='8NUVx'><q id='8NUVx'><span id='8NUVx'><b id='8NUVx'><form id='8NUVx'><ins id='8NUVx'></ins><ul id='8NUVx'></ul><sub id='8NUVx'></sub></form><legend id='8NUVx'></legend><bdo id='8NUVx'><pre id='8NUVx'><center id='8NUVx'></center></pre></bdo></b><th id='8NUVx'></th></span></q></dt></tr></i><div id='8NUVx'><tfoot id='8NUVx'></tfoot><dl id='8NUVx'><fieldset id='8NUVx'></fieldset></dl></div>
        <tfoot id='8NUVx'></tfoot>
        <legend id='8NUVx'><style id='8NUVx'><dir id='8NUVx'><q id='8NUVx'></q></dir></style></legend>

                  <bdo id='8NUVx'></bdo><ul id='8NUVx'></ul>
                    <tbody id='8NUVx'></tbody>

                  <small id='8NUVx'></small><noframes id='8NUVx'>

                • 本文介绍了mysqli_query 通过变量输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用以下 PHP 代码向 MySQL 表添加信息.(从 HTML5 基本 Web 表单输入名称和文本.)可能是语法问题?

                  I'm trying to add information to a MySQL table using the following PHP code. (The input the name and text from an HTML5 basic web form.) Probably a syntax issue?

                  <?php
                  include "dbinfo.php"; //contains mysqli_connect information (the $mysqli variable)
                  //inputs
                  $name = $_GET["name"];
                  $text = $_GET["text"];
                  
                  $sqlqr = 'INSERT INTO `ncool`.`coolbits_table` (`name`, `text`, `date`) VALUES ("$name", "$text", CURRENT_TIMESTAMP);'; //the query. I'm pretty sure that the problem is a syntax one, and is here somewhere.
                  
                  mysqli_query($mysqli,$sqlqr); //function where the magic happens.
                  ?>
                  

                  没有抛出错误.一个空白的屏幕结果,一个带有$name"和$text"的行被添加到 MySQL 表中.

                  No error is thrown. A blank screen results, and a row with "$name" and "$text" is added to the MySQL table.

                  推荐答案

                  这就是您的代码的外观(添加了 SQL 注入保护):

                  <?php
                  include "dbinfo.php"; //contains mysqli_connect information (the $mysqli variable)
                  //inputs
                  $name = mysqli_real_escape_string($_GET['name']);
                  $text = mysqli_real_escape_string($_GET['text']);
                  
                  $sqlqr = "INSERT INTO `ncool`.`coolbits_table` (`name`, `text`, `date`) VALUES ('" . $name . "', '" . $text . "', CURRENT_TIMESTAMP);";
                  
                  mysqli_query($mysqli,$sqlqr); //function where the magic happens.
                  ?>
                  

                  看看我做了什么.首先,我已经将您正在检索的用户输入转义到 $name$text 变量中(出于安全原因,这几乎是必须的),正如其他人所建议的您最好使用准备好的语句.

                  Take a look at what I've done. Firstly I've escaped the user input you're retrieving into the $name and $text variables (this is pretty much a must for security reasons) and as others have suggested you should preferably be using prepared statements.

                  问题是您没有用单引号 (') 将字符串值括起来,这是 SQL 语法的要求.

                  The problem is that you weren't surrounding string values with single quotes ('), which is a requirement of the SQL syntax.

                  我希望这有助于回答您的问题.

                  I hope this helps to answer your question.

                  这篇关于mysqli_query 通过变量输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何将表从mysql数据库导出到excel? 下一篇:致命错误:在第 62 行调用未定义的方法 Action::execute()/home/public_html/syst

                  相关文章

                  1. <small id='R2I8p'></small><noframes id='R2I8p'>

                    <legend id='R2I8p'><style id='R2I8p'><dir id='R2I8p'><q id='R2I8p'></q></dir></style></legend>

                      <i id='R2I8p'><tr id='R2I8p'><dt id='R2I8p'><q id='R2I8p'><span id='R2I8p'><b id='R2I8p'><form id='R2I8p'><ins id='R2I8p'></ins><ul id='R2I8p'></ul><sub id='R2I8p'></sub></form><legend id='R2I8p'></legend><bdo id='R2I8p'><pre id='R2I8p'><center id='R2I8p'></center></pre></bdo></b><th id='R2I8p'></th></span></q></dt></tr></i><div id='R2I8p'><tfoot id='R2I8p'></tfoot><dl id='R2I8p'><fieldset id='R2I8p'></fieldset></dl></div>

                      <tfoot id='R2I8p'></tfoot>
                      • <bdo id='R2I8p'></bdo><ul id='R2I8p'></ul>