簡體   English   中英

更新SQL表時出錯

[英]Error when Updating SQL Table

我正在嘗試使用一種表單來更新SQL數據庫中的表,但出現此錯誤

如果我的客戶ID字段的值為“ 7020”,證明字段的值為“ test”,則會出現此錯誤:無法更新數據:“字段列表”中的未知列“ test”

</head>

   <body>
      <?php
         if(isset($_POST['update']))
         {
            $dbhost = 'xxxxxxxx';
            $dbuser = 'xxxxx';
            $dbpass = 'xxxxxxxxxxxxxxxxxxxxxxxx';

            $conn = mysql_connect($dbhost, $dbuser, $dbpass);

            if(! $conn )
            {
               die('Could not connect: ' . mysql_error());
            }

            $clientid = $_POST['clientid'];
            $proof = $_POST['proof'];

            $sql = "UPDATE penalties ". "SET Proof = $proof " ."WHERE client_id = $clientid AND type='ban'";
            mysql_select_db('b3bot');
            $retval = mysql_query( $sql, $conn );

            if(! $retval )
            {
               die('Could not update data: ' . mysql_error());
            }
            echo "Updated data successfully\n";

            mysql_close($conn);
         }
         else
         {
            ?>
               <form method="post" action="<?php $_PHP_SELF ?>">
                  <table width="400" border="0" cellspacing="1" cellpadding="2">

                     <tr>
                        <td width="100">Client ID</td>
                        <td><input name="clientid" type="text" id="clientid"></td>
                     </tr>

                     <tr>
                        <td width="100">Proof</td>
                        <td><input name="proof" type="text" id="proof"></td>
                     </tr>

                     <tr>
                        <td width="100"> </td>
                        <td> </td>
                     </tr>

                     <tr>
                        <td width="100"> </td>
                        <td>
                           <input name="update" type="submit" id="update" value="Update">
                        </td>
                     </tr>

                  </table>
               </form>
            <?php
         }
      ?>
   </body>
</html>

您嘗試執行的sql查詢應該是錯誤的。 如我所見,查詢現在看起來像:

UPDATE penalties SET Proof = sth WHERE client_id = test AND type='ban'

應該是這樣的:

UPDATE penalties SET Proof = 'sth' WHERE client_id = 'test' AND type='ban'

(請注意引號)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM