#1
  1. No Profile Picture
    dchrist
    Guest
    Devshed Newbie (0 - 499 posts)
    i'm having trouble using a concatenated string in a mysql_db_query. The code below shows both the string i'm trying to use (commented) and the one that works. Any ideas on what i am tripping on?

    if ($update) {
    $update_string = "UPDATE $db_table SET ";
    for ($i=0; $i<mysql_numfields($field_results);$i++) {
    $output = mysql_fieldname($field_results, $i);
    if ($output == 'id') {continue;}
    $update_string .= " $output='".$$output."'";
    }
    #$update_string .= " WHERE id='$id'";
    $update_string = "UPDATE images SET name='test' WHERE id='11'";
    $update_result = mysql_db_query($db_database, $update_string);
    }

    by the way, when i use the commented version of $update_string, mysql_db_query doesn't return anything. Huh? What does that mean?
  2. #2
  3. No Profile Picture
    cheny
    Guest
    Devshed Newbie (0 - 499 posts)
    If you don't add a semicolon at the end of a query statement, MySQL won't know when to start executing your query.

    That is

    $update_string = ".... ;";
  4. #3
  5. No Profile Picture
    dchrist
    Guest
    Devshed Newbie (0 - 499 posts)
    the semicolon doesn't help, and i haven't used it elsewhere (ie. in the other example of $update_string). i can take the UPDATE string and use it directly (instead of using it inside of a variable), and it works. It also seems to have trouble with the length of the SQL statement. i'm suspecting that it may have something to do with the quotation marks and it being concatenated together. i've tried using addslashes(), but that doesn't help. Does anyone have an example of an UPDATE which is assembled dynamically (rather than being typed out exactly) which works? i really would appreciate the help. It's getting down to the wire on my project, but i suppose it is the same with everything. Thanks for the help.
  6. #4
  7. No Profile Picture
    cheny
    Guest
    Devshed Newbie (0 - 499 posts)
    If you need to change multiple fields, you have to seperate it with a comma.

    That is,

    Set ..=.. , ..= .. , ..=.. WHERE ..

    This is my debugging advice, always output the problem, in this case
    echo $update_string;
    Then copy the statement and then go into mysql and enter the exact same statement and see what errors it reports.

    P.S this is why I always add a semicolon at the end of a query.
  8. #5
  9. No Profile Picture
    Pointman
    Guest
    Devshed Newbie (0 - 499 posts)
    Check your PHP version. For some reason, I had problems getting UPDATE to work at all in early 3.0 versions using MySQL 3.21.xx versions. I'm using PHP 3.0.12 and MySQL 3.22.25 now and it works fine.....
  10. #6
  11. No Profile Picture
    dchrist
    Guest
    Devshed Newbie (0 - 499 posts)
    thanks for the help.

    it turns out that the problem i was having was that i forgot to include , between my sql SET statements. Silly me.

Similar Threads

  1. Converting numbered strings into int
    By C_rookie in forum C Programming
    Replies: 12
    Last Post: October 6th, 2003, 03:23 PM
  2. manipulating char * strings
    By infamous41md in forum C Programming
    Replies: 2
    Last Post: June 1st, 2003, 12:48 AM
  3. strings vs. constant strings (what's the difference?)
    By Matthew Doucette in forum C Programming
    Replies: 8
    Last Post: March 7th, 2003, 01:00 PM
  4. matching identical parts in two strings
    By mchess in forum PHP Development
    Replies: 11
    Last Post: June 14th, 2002, 03:07 AM
  5. PHP mailer wont send data strings
    By direwolf in forum PHP Development
    Replies: 7
    Last Post: March 21st, 2002, 10:10 PM

IMN logo majestic logo threadwatch logo seochat tools logo