Rommeo Posted January 16, 2018 Share Posted January 16, 2018 Hi, I have a very simple query, which is; UPDATE Vendor SET Name = '22' , Phone = '22' , Info = '22' , Rating = '20' , Status = 'active' WHERE 1=1 AND venid = '2' The weird thing is, it updates the row but it also gives me an error like; (I have the column venid in the table) Unknown column 'venid' in 'where clause' Also, when i use the query in "sql" section of phpmyadmin, it works well and does not give me any problem. Why can it be? I would be glad if anyone can help. Thanks in advance. PS: (i m using the query like : mysql_query($query) or die(mysql_error()) ) Quote Link to comment https://forums.phpfreaks.com/topic/306222-a-really-weird-update-problem/ Share on other sites More sharing options...
Solution mac_gyver Posted January 16, 2018 Solution Share Posted January 16, 2018 (edited) the error message is probably coming from some other query in your code, perhaps after the one in question, if you don't for example have an exit; statement after a header() redirect. in any case, it would take seeing all your code, less any connection credentials, to be able to specifically help find the cause of the problem. btw - the old and obsolete php mysql extension has been removed from the latest php version and you should be updating your code to use either the php PDO extension (which is the best choice) or the php mysqli extension (turns out is not a good choice at all), and you should not be putting data values directly into the sql query statement, but using a prepared query, with place-holders in the sql statement for the data values, then supply the data when you execute the query. updating the code will also let you use exceptions to handle the database statement errors, so you can simply enable exceptions for the extension you end up using, let php catch the exception, where it will use its error_reporting, display_errors, and log_errors settings to control what happens with the actual error information, and you can then eliminate any error handling logic you have in your code, thereby reducing the amount of code you have to convert. Edited January 16, 2018 by mac_gyver 1 Quote Link to comment https://forums.phpfreaks.com/topic/306222-a-really-weird-update-problem/#findComment-1555423 Share on other sites More sharing options...
Rommeo Posted January 16, 2018 Author Share Posted January 16, 2018 the error message is probably coming from some other query in your code, perhaps after the one in question, if you don't for example have an exit; statement after a header() redirect. in any case, it would take seeing all your code, less any connection credentials, to be able to specifically help find the cause of the problem. btw - the old and obsolete php mysql extension has been removed from the latest php version and you should be updating your code to use either the php PDO extension (which is the best choice) or the php mysqli extension (turns out is not a good choice at all), and you should not be putting data values directly into the sql query statement, but using a prepared query, with place-holders in the sql statement for the data values, then supply the data when you execute the query. updating the code will also let you use exceptions to handle the database statement errors, so you can simply enable exceptions for the extension you end up using, let php catch the exception, where it will use its error_reporting, display_errors, and log_errors settings to control what happens with the actual error information, and you can then eliminate any error handling logic you have in your code, thereby reducing the amount of code you have to convert. You are perfect! I checked every single item, and found the error, Noticed that it was not in this query. When I use exit it was working well. Problem was I forgot to unset the values that i have used in the array, when i find the line i fixed it. Thank you so much! Quote Link to comment https://forums.phpfreaks.com/topic/306222-a-really-weird-update-problem/#findComment-1555430 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.