dsf12313
2019-04-08 06:43
浏览 75
已采纳

如何修复错误:查询是空的查询? [重复]

This question already has an answer here:

I am updating the data in database from php and Getting Up Error:Query was empty with query. I badly need help. Thanks in Advance

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$myDBname = 'jsv';
$conn = mysql_connect("localhost", "root");
mysql_select_db('jsv');
if(isset($_POST['update']))
{
$nam = $_POST['namnid'];
$mandag = $_POST['mandagid'];
$tisdag = $_POST['tisdagid'];
$torsdag = $_POST['torsdagid'];
$fredag = $_POST['fredagid'];

$sql = mysql_query("INSERT INTO jsv(CA_ID,Name,Address,Amount)  VALUES ('$mandag', '$tisdag', '$torsdag', '$fredag') WHERE Setup_Box_No = '$nam'", $conn);
if(!$sql )
{
  die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully
";

}

mysql_close($conn);
?>
</div>

图片转代码服务由CSDN问答提供 功能建议

此问题已经存在 这里有一个答案:

  • MySQL插入位置查询 25 answers \ r

    我正在更新数据库中的数据从php和Get Up Error:Query为空查询。 我非常需要帮助。 在此先感谢

     &lt;?php 
     $ dbhost ='localhost'; 
     $ dbuser ='root'; 
     $ myDBname ='jsv'; 
      $ conn = mysql_connect(“localhost”,“root”); 
    mysql_select_db('jsv'); 
    if(isset($ _ POST ['update']))
     {
     $ nam = $ _POST ['namnid'  ]; 
     $ mandag = $ _POST ['mandagid']; 
     $ tisdag = $ _POST ['tisdagid']; 
     $ torsdag = $ _POST ['torsdagid']; 
     $ fredag​​ = $ _POST ['  fredag​​id']; 
     
     $ sql = mysql_query(“INSERT INTO jsv(CA_ID,Name,Address,Amount)VALUES('$ mandag','$ tisdag','$ torsdag','$ fredag​​')WHERE Setup_Box_No  ='$ nam'“,$ conn); 
    if(!$ sql)
     {
     die('无法更新数据:'。mysql_error()); 
    } 
    echo”已成功更新数据
    “  ; 
     
    } 
     
    mysql_close($ conn); 
    ?&gt; 
       
     
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtcaw02086 2019-04-08 06:54
    已采纳

    MySQL does not support a WHERE clause in an INSERT statement. This causes your query to fail & makes $sql false.

    You will need to rewrite your INSERT statement.

    This answer should give you more explanation on alternative queries.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题