【问题标题】:DELETE unknown column 'int value' in 'where clause'删除“where子句”中的未知列“int value”
【发布时间】:2013-10-27 14:29:33
【问题描述】:

我有一个表,其中有一个名为 link_id 的 A_I 列。当我这样跑时:

$link_id = 32;
$query1 = "DELETE FROM links WHERE link_id = $link_id";
if(!mysql_query($query1,$connection));
{
    die(mysql_error($connection));
}

它可以成功运行,但是当我使用 C# WebRequest 尝试此操作时:

WebRequest request = WebRequest.Create("http://www.mywebsite.com/deleteLink.php");
request.Method = "POST";
string post = "link_id=" + id //type string;
byte[] postBytes = Encoding.UTF8.GetBytes(post);
request.ContentLength = postBytes.Length;
request.ContentType = "application/x-www-form-urlencoded";
Stream dataStream = await request.GetRequestStreamAsync();
dataStream.Write(postBytes, 0, postBytes.Length);
WebResponse response = await request.GetResponseAsync();
return new StreamReader(response.GetResponseStream()).ReadToEnd();

返回:'where 子句'中的未知列'32'

我哪里做错了?谢谢。

【问题讨论】:

  • 出于安全和良好实践的原因,您应该正确地参数化您的查询。它还避免了这种情况下的混淆。众多示例之一here
  • 我认为你的东西只在 C# MySQL 之间,但我想要 C# PHP MySQL。所以我需要使用 webrequests 来连接 PHP。
  • @user2770705 请尝试byte[] postBytes = ASCIIEncoding.Default.GetBytes(post);

标签: c# php mysql sql sql-delete


【解决方案1】:

也许在您的查询中在 $link_id 周围添加单引号

$query1 = "DELETE FROM links WHERE link_id = '$link_id'";

【讨论】:

  • 但它是 A_I 值,所以我认为它应该是整数。我也把它做成了 int 值。
猜你喜欢
  • 1970-01-01
  • 2011-06-03
  • 1970-01-01
  • 1970-01-01
  • 2021-09-19
  • 2020-06-28
  • 2021-07-02
  • 2019-08-14
相关资源
最近更新 更多