Parse error: syntax error, unexpected '-', expecting ',' or ')'

Discussion in 'PHP' started by tyankee, Aug 22, 2012.

  1. #1
    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);

    ?>
     
    tyankee, Aug 22, 2012 IP
  2. afstanislav

    afstanislav Greenhorn

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    16
    #2
    you need change to this part - $retail_price, $wholesale_price
     
    afstanislav, Aug 22, 2012 IP
  3. afstanislav

    afstanislav Greenhorn

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    16
    #3
    A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ )
     
    afstanislav, Aug 22, 2012 IP
  4. tyankee

    tyankee Well-Known Member

    Messages:
    1,023
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    150
    #4
    when i change to retail_price and wholesale_price on line 16 i get other errors:

    Unknown column 'retail' in 'field list'
     
    tyankee, Aug 22, 2012 IP
  5. afstanislav

    afstanislav Greenhorn

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    16
    #5
    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.
     
    afstanislav, Aug 22, 2012 IP
  6. tyankee

    tyankee Well-Known Member

    Messages:
    1,023
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    150
    #6
    thanks what do you mean?? there is no update statement?? i'm a newbie to this.... what should it look like??
     
    tyankee, Aug 22, 2012 IP
  7. tyankee

    tyankee Well-Known Member

    Messages:
    1,023
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    150
    #7
    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
     
    tyankee, Aug 22, 2012 IP
  8. tyankee

    tyankee Well-Known Member

    Messages:
    1,023
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    150
    #8
    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.
     
    tyankee, Aug 22, 2012 IP
  9. afstanislav

    afstanislav Greenhorn

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    16
    #9
    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
     
    afstanislav, Aug 23, 2012 IP
  10. tyankee

    tyankee Well-Known Member

    Messages:
    1,023
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    150
    #10
    yikes - i just figured it out.. i was reading the wrong table... thank you for all your help..
     
    tyankee, Aug 23, 2012 IP