本文介绍了PHP/MySQL更新代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正试图从php调用行更新到mysql数据库.它失败了,但是当我尝试调用格式完全相同的插入新行时.
I'm trying to call a row update from php to an mysql database. It fails out but when i try to call an insert new row formated just the same it works.
$result = mysql_query("INSERT INTO auth (username, password, studycode, description, server) VALUES ('$username', '$password', '$studycode', '$description', '$server')");
但是此代码失败
$result = mysql_query("UPDATE auth SET username='$username', password='$password', studycode='$studycode', description='$description', server='$server' WHERE index='$id' LIMIT 1;");
index是第一列及其表的键/ID.
index is the first column and its the key/id for the table.
好的,所以我刚进入mysql admin并尝试了我的代码将发送的确切命令来跟踪错误.
Ok so i just went into mysql admin and tried the exact command my code would have sent to track the error.
UPDATE auth SET username='username', password='password', studycode='ab9102y', description='test change', server='server2' WHERE index='5' LIMIT 1;
给我错误
#1064 - 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 'index='5' LIMIT 1' at line 1
推荐答案
可能是带有索引的保留关键字问题.试试:
Possibly a reserved keyword issue with index. Try:
$result = mysql_query("UPDATE auth SET username='$username', password='$password', studycode='$studycode', description='$description', server='$server' WHERE `index` ='$id'");
这篇关于PHP/MySQL更新代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!