need help with this simple program.. can't get rid of this error.. Parse error: syntax error, unexpected '-', expecting ',' or ')' in /home/honor/public_html/query.php on line 16 line 16 is this: while (list($itemno, $retail-price, $wholesale-price) = mysql_fetch_array($result)) { here is the entire program.. <?php $sql_host = 'localhost'; $sql_database = 'databasename'; $sql_username = 'username'; $sql_password = 'password'; $sql_connect = mysql_connect($sql_host, $sql_username, $sql_password) or die(mysql_error()); mysql_select_db($sql_database, $sql_connect) or die(mysql_error()); // Lets only select 10 entries at a time, to keep server resources down // Selects 10 random entries at a time, run it via cron every minute if you have thousands of products // Table 2 Updates only if it hasnt been updated before $result = mysql_query("SELECT itemno, retail-price, wholesale-price FROM mr_products ORDER BY itemno ASC LIMIT 10") or die(mysql_error()); while (list($itemno, $retail-price, $wholesale-price) = mysql_fetch_array($result)) { // Update table 2 // You havent provided table #2 name, Update it in following query mysql_query("ss_products SET price = '{$retail_price}', wholesale_price = '{$wholesale_price}', sale_price = (sale_price * 0.95) WHERE LegacyID = $itemno AND price != '{$retail_price}'") or die(mysql_error()); } mysql_close($sql_connect); ?>
when i change to retail_price and wholesale_price on line 16 i get other errors: Unknown column 'retail' in 'field list'
SELECT itemno, retail-price, wholesale-price - why you use - in your MySQL fields? Use _ And i think you forgot UPDATE in 20 row ss_products SET price.
thanks what do you mean?? there is no update statement?? i'm a newbie to this.... what should it look like??
i updated the sql fields to have _ in them and now i'm getting further but there is something wrong with this line: mysql_query("ss_products SET price = '{$retail_price}', wholesale_price = '{$wholesale_price}', sale_price = (price * 0.95) WHERE LegacyID = $itemno AND price != '{$retail_price}'") or die(mysql_error()); it gives this error message: 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 'ss_products SET price = '139.00', wholesale_price = '97.30', sale_price = (price' at line 1
fixed the initial problems now have another one.. here is the new coding: $result = mysql_query("SELECT itemno, retail_price, wholesale_price FROM mr_products ORDER BY itemno ASC limit 10") or die(mysql_error()); while (list($itemno, $retail_price, $wholesale_price) = mysql_fetch_array($result)) { // Update table 2 mysql_query("update ss_products SET list_price = ($wholesale_price * 2), wholesale_price = {$wholesale_price}, price = ($wholesale_price * 1.25) WHERE LegacyID = '{$itemno}'") or die(mysql_error()); but it's not updating anything and i'm pretty sure it has to do with the fact that the itemno field is now defined as varchar instead of integer. when it's defined as integer and i take the quotes and brackets out, it updates fine..l but when i redefine the itemno field to be varchar (which i have to since it contains letters), i can't get it to update.. there are no errors, it just doesn't update.
First try to print your query: echo "update ss_products SET list_price = ($wholesale_price * 2), wholesale_price = {$wholesale_price}, price = ($wholesale_price * 1.25) WHERE LegacyID = '{$itemno}'"; Then try to execute printed query in phpmyadmin. If you don't get any errors try to check LegacyID if this ID available in your table which you try to update