mysql语法错误插入小数,时间戳与php

发布于 2024-09-10 06:11:24 字数 568 浏览 7 评论 0原文

我收到错误:

您的 SQL 语法有错误;检查手册 与您的 MySQL 服务器版本相对应,以便使用正确的语法 第 1 行“10”、“16:39:02”、“292.35”)' 附近

这是我在 php 中运行的查询:

mysql_query("INSERT INTO `copper` 
              (`month`, `time`, `price`) 
             VALUES 
              ('$month', '$time', '$price')") or die(mysql_error());

这是一个文字示例:

INSERT INTO `table` 
  (`month`, `time`, `price`) 
VALUES 
  ('10', '16:39:02', '292.35')

这是我的表设置

替代文字

Im getting the error:

You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '10', '16:39:02', '292.35')' at line 1

this is the query im running in php:

mysql_query("INSERT INTO `copper` 
              (`month`, `time`, `price`) 
             VALUES 
              ('$month', '$time', '$price')") or die(mysql_error());

Here is a literal example:

INSERT INTO `table` 
  (`month`, `time`, `price`) 
VALUES 
  ('10', '16:39:02', '292.35')

this is my table setup

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撩动你心 2024-09-17 06:11:24

这应该像您发布的那样工作,因此这里有一些疯狂的猜测:

您确定 $month 不包含 ' 吗?

您确定这些引用确实是正确的吗?即不是当今文字处理程序中出现的异国情调的东西? (您是从网络/pdf/doc 复制并粘贴此内容吗?)

否则,会丢失查询中的换行符,这应该不重要,但您永远不知道。

This should work as you posted it, so here's a few wild guesses:

Are you sure $month doesn't contain a '?

Are you sure those are actually the right kind of quotes? i.e. not the exotic stuff that comes out of word processors these days? (did you copy&paste this from the web / pdf / doc?)

Otherwise, lose the newlines within the query, shouldn't matter but you never know.

木森分化 2024-09-17 06:11:24

回显您的实际查询,以便您可以看到生成的内容。

$query = "INSERT INTO `copper` (`month`, `time`, `price`) VALUES ('$month', '$time', '$price')";   
mysql_query($query) or die(mysql_error() . '<br />Query: ' . $query);

echo out your actual query so you can see what is generated.

$query = "INSERT INTO `copper` (`month`, `time`, `price`) VALUES ('$month', '$time', '$price')";   
mysql_query($query) or die(mysql_error() . '<br />Query: ' . $query);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文