<bdo id='ZBqtZ'></bdo><ul id='ZBqtZ'></ul>
  1. <small id='ZBqtZ'></small><noframes id='ZBqtZ'>

  2. <tfoot id='ZBqtZ'></tfoot>
    <legend id='ZBqtZ'><style id='ZBqtZ'><dir id='ZBqtZ'><q id='ZBqtZ'></q></dir></style></legend>

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

      PHP:在单个查询中更新多个 MySQL 字段

      时间:2024-08-23

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

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

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

                本文介绍了PHP:在单个查询中更新多个 MySQL 字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我基本上只是想更新表中的多个值.解决此问题的最佳方法是什么?这是当前代码:

                I am basically just trying to update multiple values in my table. What would be the best way to go about this? Here is the current code:

                $postsPerPage = $_POST['postsPerPage'];
                $style = $_POST['style'];
                
                mysql_connect ("localhost", "user", "pass") or die ('Error: ' . mysql_error());
                mysql_select_db ("db");
                
                mysql_query("UPDATE settings SET postsPerPage = $postsPerPage WHERE id = '1'") or die(mysql_error());
                

                我想包含的另一个更新是:

                The other update I want to include is:

                mysql_query("UPDATE settings SET style = $style WHERE id = '1'") or die(mysql_error());
                

                谢谢!

                推荐答案

                使用逗号分隔添加多个列:

                Add your multiple columns with comma separations:

                UPDATE settings SET postsPerPage = $postsPerPage, style= $style WHERE id = '1'
                

                但是,您没有清理您的输入?这意味着任何随机黑客都可能破坏您的数据库.看到这个问题:什么是清理用户输入的最佳方法用 PHP 吗?

                However, you're not sanitizing your inputs?? This would mean any random hacker could destroy your database. See this question: What's the best method for sanitizing user input with PHP?

                另外,样式是数字还是字符串?我假设一个字符串,所以它需要被引用.

                Also, is style a number or a string? I'm assuming a string, so it would need to be quoted.

                这篇关于PHP:在单个查询中更新多个 MySQL 字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:PHP MYSQL UPDATE 如果存在或 INSERT 如果不存在? 下一篇:在 MySQL UPDATE (PHP/MySQL) 中使用变量

                相关文章

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

                1. <tfoot id='1BomM'></tfoot>

                2. <legend id='1BomM'><style id='1BomM'><dir id='1BomM'><q id='1BomM'></q></dir></style></legend>
                      <bdo id='1BomM'></bdo><ul id='1BomM'></ul>

                    <small id='1BomM'></small><noframes id='1BomM'>