简体   繁体   中英

update mysql database using php

I'm trying to update my users table using 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

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?

When using UPDATE, MySQL will not update columns where the new value is the same as the old value. 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.

http://us1.php.net/manual/en/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

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM