Jump to content

A really weird update problem


Rommeo
Go to solution Solved by mac_gyver,

Recommended Posts

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

 

 

 

 

Link to comment
Share on other sites

  • Solution

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 by mac_gyver
  • Like 1
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.