[英]update mysql database using php
I'm trying to update my users table using php. 我正在尝试使用php更新我的用户表。
$update_query="
UPDATE `users` SET `name`='$addname',
`lastname`='$addlastname',
`password`='$addpsswrd',
`email`='$addemail'
where `username`='$modifyusername'
";
echo $update_query;
if( mysql_query($update_query) or die('Erreur SQL !'.$req.'<br>'.mysql_error()))
echo "Lignes modifiées : ", mysql_affected_rows();
But I always get : 但是我总是得到:
UPDATE `users` SET `name`='Jolia ',`lastname`='roberta', `password`='password1234',`email`='roberta.joli@hotmail.fr' where `username`='user11'
Lignes modifiées : 0 木质修改:0
How can I fix this? 我怎样才能解决这个问题? the user11 exist in my database and I tried to copy past this query as it is in the output echo message I get 0 modified line so how can I fixed on the php part? user11存在于我的数据库中,我尝试复制此查询,因为它在输出echo消息中显示为0,所以我如何在php部分上进行固定?
When using UPDATE, MySQL will not update columns where the new value is the same as the old value. 使用UPDATE时,MySQL不会更新新值与旧值相同的列。 This creates the possibility that mysql_affected_rows() may not actually equal the number of rows matched, only the number of rows that were literally affected by the query. 这可能会导致mysql_affected_rows()可能实际上不等于匹配的行数,而实际上不等于查询实际影响的行数。
http://us1.php.net/manual/en/function.mysql-affected-rows.php http://us1.php.net/manual/zh/function.mysql-affected-rows.php
I am not sure , but my suggestion is try to remove the single quotation marks ['] from the column name. 我不确定,但是我的建议是尝试从列名中删除单引号[']。 ps: this is my first time answer question on stackoverflow ps:这是我第一次在stackoverflow上回答问题
like 喜欢
$update_query="
UPDATE users SET name='$addname',
lastname='$addlastname',
password='$addpsswrd',
email='$addemail'
where username='$modifyusername'
";
echo $update_query;
if( mysql_query($update_query) or die('Erreur SQL !'.$req.'<br>'.mysql_error()))
echo "Lignes modifiées : ", mysql_affected_rows();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.