doupu1957 2015-04-14 10:15
浏览 41
已采纳

如何使用变量更新mysql数据库?

To all experts who is going to read this question, It is a basic problem that cost me more than hours to me,

I want to update previously entered row. As it can be seen in the code, I want to update Improvement column. Also I want to do that with the help of the last user id, which is a auto increment primary key entry. However with the code I wrote down here nothing changes in my Mysql database.

$sql = "
UPDATE users 
SET Improvement='".$improvement."'
WHERE ORDER BY User_id DESC LIMIT 1 
";  

mysql_query($sql, $accounts);

And as you can see this is my table in mysql,

users   CREATE TABLE `users` (
 `Username` varchar(30) COLLATE latin1_general_ci NOT NULL,
 `Age` varchar(20) COLLATE latin1_general_ci NOT NULL,
 `Education` varchar(20) COLLATE latin1_general_ci NOT NULL,
 `Department` varchar(20) COLLATE latin1_general_ci NOT NULL,
 `Favourite` varchar(20) COLLATE latin1_general_ci NOT NULL,
 `Preference` varchar(20) COLLATE latin1_general_ci NOT NULL,
 `Lpreference` varchar(20) COLLATE latin1_general_ci NOT NULL,
 `Level` varchar(20) COLLATE latin1_general_ci NOT NULL,
 `Question` varchar(20) COLLATE latin1_general_ci NOT NULL,
 `Improvement` int(11) NOT NULL,
 `User_id` int(11) NOT NULL AUTO_INCREMENT,
 PRIMARY KEY (`User_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci

I believe I cannot update Improvement column because of the syntax. In my page no error occurs, and nothing happens even though $improvement not equal to 0. I echo the $improvement variable it is not equal to 0. But noting changes in my database.

I am desperate for an answer, If it works I will select it as best answer for other people who is facing the same problem.

  • 写回答

4条回答 默认 最新

  • donglin6313 2015-04-14 10:20
    关注

    Try with -

    $sql = "UPDATE users SET Improvement='".$improvement."' ORDER BY User_id DESC LIMIT 1";  
    
    mysql_query($sql, $accounts);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路