[英]PHP update query successful but database not updating
Seems like you're using PDO (hopefully)似乎您正在使用 PDO(希望如此)
When you're using this Data Objects, when a query is executed it will return TRUE, but it doesn't care if it changed something or not, it will return true when there is not a critical MYSQL Error.当你使用这个数据对象时,当一个查询被执行时它会返回 TRUE,但它并不关心它是否改变了某些东西,当没有关键的 MYSQL 错误时它会返回 true。
What you want to do is to know IF A ROW AS AFFECTED / CHANGED by that query, in that case instead of using;你想要做的是知道如果 A ROW AS AFFECTED / CHANGED 通过该查询,在这种情况下而不是使用;
$PDOObject->query($thequery) == true
you should use:你应该使用:
$result = $PDOObject->query($thequery);
if($result->rowCount() > 0) ...
More info about how to know if a row was affected by a query with PDO有关如何知道行是否受 PDO 查询影响的更多信息
http://php.net/manual/en/pdostatement.rowcount.php http://php.net/manual/en/pdostatement.rowcount.php
sql query return successful but my database is not changing
sql查询返回成功但我的数据库没有改变
Are you sure that there exists at least one record that matches your filter criteria WHERE full_name = '$full_name' AND representative_id = '$login_session'
.您确定至少存在一条符合您的过滤条件
WHERE full_name = '$full_name' AND representative_id = '$login_session'
。 If no record updating means no any record matching the WHERE
condition and so no updates occurring.如果没有记录更新意味着没有任何与
WHERE
条件匹配的记录,因此不会发生更新。
representative_id = '$login_session'
Is the representative_id
column in your table a VARCHAR
, or an INT
?您表中的
representative_id
_id 列是VARCHAR
还是INT
? You're passing a string to MySQL, there.您正在向 MySQL 传递一个字符串。 If the column in your DB is stored as an
INT
, try removing the single quotes around $login_session
.如果数据库中的列存储为
INT
,请尝试删除$login_session
周围的单引号。
When posting questions relating to database queries, it helps to also include your table schema.在发布与数据库查询相关的问题时,还包括您的表架构会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.