Table updating works only occasionally.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sunday@hotmail.com

    Table updating works only occasionally.

    When trying to update a table, the following works only occasionally;
    it doesn't work reliably. Can anyone show me where I'm going wrong,
    please?

    // $commenrts_new is the data from the form ;

    $Query="SELECT comments FROM clients WHERE id='$cli_update _id' ";
    $Result=mysql_d b_query ($DBName, $Query, $Link);
    while ($Row=mysql_fet ch_array ($Result))
    {
    $comments_old=$ Row[comments];
    }
    $comments=$comm ents_old." <br>".$comments _new;
    $Query="UPDATE clients SET comments='$comm ents' WHERE
    id='$cli_update _id' ";
    $Result=mysql_d b_query ($DBName, $Query, $Link);

    TIA.
  • Rik Wasmus

    #2
    Re: Table updating works only occasionally.

    On Tue, 11 Mar 2008 08:47:10 +0100, <sunday@hotmail .comwrote:
    When trying to update a table, the following works only occasionally;
    it doesn't work reliably. Can anyone show me where I'm going wrong,
    please?
    >
    // $commenrts_new is the data from the form ;
    >
    $Query="SELECT comments FROM clients WHERE id='$cli_update _id' ";
    Where does $cli_update_id come from, and is it sanatised?
    $Result=mysql_d b_query ($DBName, $Query, $Link);
    if(!$Result) echo mysql_error();//or log mysql_error() to a file in case
    of a live website
    while ($Row=mysql_fet ch_array ($Result))
    {
    $comments_old=$ Row[comments];
    }
    $comments=$comm ents_old." <br>".$comments _new;
    $comments = mysql_real_esca pe_string($comm ents);
    $Query="UPDATE clients SET comments='$comm ents' WHERE
    id='$cli_update _id' ";
    $Result=mysql_d b_query ($DBName, $Query, $Link);
    Again:
    if(!$Result) echo mysql_error();//or log mysql_error() to a file in case
    of a live website

    I'd say the most likely scenario for failure is a ' in either
    $comments_old or $comments_new.

    Also: why not do this:

    $cli_update_id = mysql_real_esca pe_string($cli_ update_id);
    $comments_new = mysql_real_esca pe_string($comm ents_new);
    mysql_query("UP DATE clients SET comments =
    CONCAT(comments ,'<br>','$comme nts_new' WHERE id = '$cli_update_id '");
    --
    Rik Wasmus

    Comment

    • sunday@hotmail.com

      #3
      Re: Table updating works only occasionally.

      Thank you. I put in some of your code (particularly the escape_string
      and the CONCAT bits) and it seems to do the business on all the trials
      I've made of it. I'll keep an eagle eye on it throughout the next few
      days.

      Thanks again.

      Comment

      Working...