Hi. I need your help. I don't know if this topic is to be posted here or in MySQL sub-forum but i think this will be easy for you. I have a PHP script with this. $count = 3 for($i = 0;$i < $count; $i++) { $abcde = $result['example'][$i]; $id = $i+1; Then, after i connect the MySQL DB i have this: $query = "UPDATE table_name SET field_name = '$abcde' where id='$id'"; mysql_query($query) or die (mysql_error()); All i want to do is to update some fields of one of my db's table with a variable. I mean, this code works perfectly if i replace $abcde at the UPDATE row for simple text, no variable. If i do this, the text is added to all fields i want to modify perfectly, but if i use a variable like $abcde just the field where id=1 (just the first one, in this case) is updated. Just the first one is updated perfectly, the others two are not modified because the system gives to me an error that says: 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 By testing, i think i have to put the variable at the UPDATE row using another syntax. Can someone help me with this, saying to me how to write the variable in this point to get my table's fields updated with the information depending of the value of $abcde??? Thanks in advance!!! Reinaldo. P.D.: Sorry for my english, i know it isn't very good.
Do an echo of $query and see what it looks like. You might also want to post the whole script, or at least the whole part that is interested, instead of only some bits and pieces.
I've tried that but it still doesn't working. I don't know what to do... Can anybody else help me?. I think the problem is in UDPATE row but i'm not sure because it works fine with any text and with variables just work fine for the first cycle of the loop, after this, when the code arrives to the UPDATE row for second time the system gives to me an error, this: 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.... Can you help me with this. Thank you. Reinaldo.
wont $i always be < (less than) $count .. since $i = 0 and $count=3 1 2 3 4 5 6 7 8 9 10 To infinity ...and Beyond! j/k $i = 0; while ($i <= 3) { echo $i++; }