cyberdoc Posted July 9, 2014 Share Posted July 9, 2014 Hi guys, sorry for such a silly php query but tried too much and not working. Am missing something silly. $sub_total = $result['textarea']; $newpro=$result['mainid']; echo ($sub_total); $result = Db::getInstance()->Execute('UPDATE `'. _DB_PREFIX_ .'product` SET `price` = ' .$sub_total. ' WHERE `id_product` = 9'); i use this query to update the product table. now the echo sub_total gives the correct value(10) but the sql is not run with the error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `id_product` = 9' at line 1 UPDATE `ps_product` SET `price` = WHERE `id_product` = 9 now from this it seems no values is being passed for sub_total but how and why this could happen Link to comment Share on other sites More sharing options...
prstshp_joe Posted July 9, 2014 Share Posted July 9, 2014 Your quotes look a bit messed up. Try to remove them for ' .$sub_total. ' Link to comment Share on other sites More sharing options...
bellini13 Posted July 9, 2014 Share Posted July 9, 2014 The price column is a decimal and does not require quotes to surround the value, like a varchar would. This means that your code looks correct. If I execute the following SQL command on my localhost it works properly, and this matches your SQL command. So there is something else we are not seeing. UPDATE `ps_product` SET `price` = 10 WHERE `id_product` =9; I would suggest you rewrite your code to this and then show us what the output of $sql is. You should take that output and execute the command directly in phpmyadmin to see what the error is $sql = 'UPDATE `'. _DB_PREFIX_ .'product` SET `price` = ' .$sub_total. ' WHERE `id_product` = 9'; echo $sql; $result = Db::getInstance()->Execute($sql); Link to comment Share on other sites More sharing options...
cyberdoc Posted July 9, 2014 Author Share Posted July 9, 2014 hi thanks for ur reply. i tried the directly phpmyadmin way already and it works nicely. its only when im using these variables. and the stramge this is if i echo sub_total before executing the sql code , it also outputs proper value just in the statement its not being passed. cant figure whats wrong in the syntax.. Link to comment Share on other sites More sharing options...
bellini13 Posted July 9, 2014 Share Posted July 9, 2014 so you didn't do what I suggested to do? Link to comment Share on other sites More sharing options...
cyberdoc Posted July 9, 2014 Author Share Posted July 9, 2014 (edited) trying via phpmyadmin na? did it that works na i said above.. Edited July 9, 2014 by cyberdoc (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted July 10, 2014 Share Posted July 10, 2014 no, i suggested rewritting your code so you echo the EXACT sql statement that is being executed by Prestashop, then take that statement and execute it using phpmyadmin. There is obviously a difference in the statement you want to execute, versus the statement that is executing.... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now