Jump to content

Silliest php issue


cyberdoc

Recommended Posts

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 :unsure:  :blink: 

Link to comment
Share on other sites

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...