I think I know the answer to this but want to get confirmation.
If you have a simple update query with a where clause and the value of the variable in the where clause is missing, does that mean every record gets updated?
//let's say $name is empty
UPDATE users SET name= 'Jason' WHERE userid = '$name'
is that the same as
UPDATE users SET name= 'Jason' WHERE userid = ''
Is the behavior that every record would get updated?
And, if so, is there anything you can put in the SQL to prevent this potential catastrophe?
Thanks for guidance.
Both queries will update all records where userid
column is empty. But it doesn't means that rows with userid
value which is equal to NULL
will be affected. If you want to use WHERE
against NULL
column, read how to working with NULL values .
如果变量为空,或者没有值或“”,并且在您的表上没有userid
为空或null的记录,则不会更新任何记录,因为where条件将不希望有任何记录,但是如果存在任何具有空userid
的记录,那么该记录将使用您提供给相应列的值进行更新。
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.