Updating Database

Discussion in 'PHP' started by PedroG, Jun 16, 2010.

  1. #1
    i´me trying to update a database column with the values i get with COUNT on the database.

    <?
    include("con.php");
    $mysql = new conexao;
    $listaclientes = $mysql->sql_query("SELECT file_author, COUNT(file_author) FROM phcdl_files GROUP BY file_author;");
    $mysql->desconecta;while($clientes= mysql_fetch_array($listaclientes)){
    $mysql->sql_query("UPDATE LOW_PRIORITY phcdl_users SET user_uploads=".clientes['COUNT(name)'] ." where file_author = $clientes['file_author'];");
    }
    ?>
    
    
    Code (php):
    However, the page retrieves this >
    Parse error: syntax error, unexpected '[' in /home2/antivir5/public_html/legendaspt/perso/updater.php on line 20

    I´me noob in php, so the codes are what i found in searches, i already found one with wich i could output the nr of uploads for each user, but what i i reallly need is to update the database

    Does someone knows what´s the problem??
     
    PedroG, Jun 16, 2010 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    try this
    <?
    include("con.php");
    $mysql = new conexao;
    $sql = "SELECT file_author, COUNT(file_author) FROM phcdl_files GROUP BY file_author";
    $listaclientes = $mysql->sql_query($sql) or die(mysql_error().'<br>'.$sql);
    //$mysql->desconecta;
    while($clientes= mysql_fetch_array($listaclientes)){
       $sql = "UPDATE LOW_PRIORITY phcdl_users SET user_uploads='{$clientes['COUNT(name)']}' where file_author = '{$clientes['file_author']}'";
       $mysql->sql_query($sql) or die(mysql_error().'<br>'.$sql);
    }
    ?>
    PHP:
     
    sarahk, Jun 16, 2010 IP
  3. PedroG

    PedroG Member

    Messages:
    59
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    " Unknown column 'file_author' in 'where clause' "

    the "file_author" is in the "phcdl_files" table, and the "user_uploads" is on the "phcdl_users"
    Is something related to that , the problem?
     
    PedroG, Jun 17, 2010 IP
  4. PedroG

    PedroG Member

    Messages:
    59
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #4
    bump
    sorry for, but do you know how can i solve the problem?
    as i just said yd both columns are in diferent tables, what could i do to fix the problem?
     
    PedroG, Jun 18, 2010 IP
  5. Lam3r

    Lam3r Active Member

    Messages:
    235
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Try this, I think the problem is with your apostrophes and quotes:
    
    <?
    include("con.php");
    $mysql = new conexao;
    $listaclientes = $mysql->sql_query("SELECT file_author, COUNT(file_author) FROM phcdl_files GROUP BY file_author;");
    $mysql->desconecta;while($clientes= mysql_fetch_array($listaclientes)){
    $mysql->sql_query("UPDATE LOW_PRIORITY phcdl_users SET user_uploads="'".clientes['COUNT(name)'] ."'" where file_author = $clientes['file_author'];");
    }
    ?>
    PHP:
     
    Lam3r, Jun 19, 2010 IP
  6. PedroG

    PedroG Member

    Messages:
    59
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #6
    something stills wrong :(
    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home2/antivir5/public_html/legendaspt/perso/updata.php on line 6
    Code (markup):
     
    PedroG, Jun 19, 2010 IP
  7. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #7
    I stand by my code but I was relying on the essence of your sql to be right. Might pay to let us know the table structure (columns).
     
    sarahk, Jun 19, 2010 IP