English 中文(简体)
MySQL 问题,编号[复制]
原标题:MySQL issue with UPDATE numbers [duplicate]
  • 时间:2011-03-28 15:48:54
  •  标签:
  • php
  • mysql

我试图用PHP做一个非常简单的UPDATE。

$nlk = $lk + "1";
mysql_query("UPDATE posts SET like =  ".$nlk."  WHERE id =  ".$cid." ") or die(mysql_error());

$lk is a the value gotten from the field like, which is default 0. $cid is a value from an id field, which is on auto_increment.

我发现这一错误:

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 like = 1 WHERE id = 45 at line 1

这里的问题是什么?

最佳回答

使用该栏():

mysql_query("UPDATE posts SET `like` =  ".$nlk."  WHERE id =  ".$cid." ") or die(mysql_error());

Better yet, don t use reserved words as table/column names.

问题回答

就像一个保留词。 你们需要用背书的方式来加以克服。

mysql_query("UPDATE posts SET `like` =  ".$nlk."  WHERE id =  ".$cid." ") or die(mysql_error());

<代码>类似为保留关键词。 See here, for a list of reservations keywords in mysql. 如果你随附,如-Column in remaps (`),该错误就应当删除。

<代码>如是MySQL的关键词。 情况最有可能如此。 要么试图放弃实地名称

mysql_query("UPDATE posts SET `like` =  ".$nlk."  WHERE id =  ".$cid." ") or die(mysql_error());

或者,如果你重犯同一错误,将实地名称改为别的东西。

Like is a keyword in SQL. This could cause your error. Change your column name, or, at least, add the table name in front of your "like".

因为LKE是一个关键词。 采用对应标准。

http://dev.mysql.com/doc/refman/5.0/en/servd-words.html” rel=“nofollow”

页: 1

mysql_query("UPDATE posts SET `like` =  ".$nlk."  WHERE id =  ".$cid." ") or die(mysql_error());

背着你错误的信息,靠近WHERE id = 45”。

This query will probably run if replace the double quotation mark with a single.

-gz

我的坏处,我错过了像保留词前面的主要一面,并且看到的是非单体空间,因此,最后两个单一体会翻一番。 期限。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...