September 10th, 1999, 01:52 PM
-
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?
September 10th, 1999, 02:28 PM
-
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 = ".... ;";
September 10th, 1999, 02:36 PM
-
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.
September 10th, 1999, 03:23 PM
-
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.
September 11th, 1999, 02:22 PM
-
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.....
September 13th, 1999, 10:03 AM
-
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.