duandui2803 2014-02-22 20:40
浏览 148
已采纳

SQL INSERT INTO查询出错

I have following code written in PHP:

  $q = mysql_query("INSERT INTO logowania ('user','udane','ip') VALUES ($uid,0,'".ip()."')"); echo mysql_error();

Values of $uid and ip() are correct, you can trust me.

Structure of logowania table:

1   idlogowania     int(11)             

2   user    int(11) 

3   udane   tinyint(1)  

4   data    timestamp       on update CURRENT_TIMESTAMP     CURRENT_TIMESTAMP   ON UPDATE CURRENT_TIMESTAMP     

5   ip  text    utf8_polish_ci  

I don't know where is the error in the statement. MySQL gives:

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 ''user','udane','ip') VALUES (1,0,'79.184.7.44')' at line 1

I tried to debug that, but without successful ending. I know that could be very simple mistake, but human's vision isn't infallible...

  • 写回答

3条回答 默认 最新

  • dswfyq6201 2014-02-22 20:41
    关注

    Use back ticks for column name,otherwise they are treated as strings.

    (`user`,`udane`,`ip`)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)