Jump to content

[SOLVED] My UPDATE fails =/


Bisa

Recommended Posts

I'm trying to update some rows in my db using this query in a while-loop

mysql_query('UPDATE eqdkp_members SET member_attendance = ' . $percent_of_raids . ' WHERE member_name = ' . $row['member_name'] . '');

 

To make sure I'm having variables n' stuff sorted I entered this echo:

echo $row['member_name'] . ' - ' . $percent_of_raids . '<br />';

which gives me the following output:

User1 - 60
User2 - 40
User3 - 8
User4 - 99

 

As you can see the $row['member_name'] and $percent_of_raids change accordingly throughout the while-loop but if I check my database the same old default values are still there, no updates have been made (and Mind you I do get the $row['member_name'] from the same database  :D)

 

Any help would be appreciated  :-\

Link to comment
https://forums.phpfreaks.com/topic/135371-solved-my-update-fails/
Share on other sites

You can do this multiple ways.  But the easiest for me would be to use the double quotes for the entire string and single quotes for the strings that you're updating.  Of course you could escape but I personally don't like to do that.  If you put {} around arrays it won't cause any errors in your string.  I haven't tested this:

 

mysql_query("UPDATE eqdkp_members SET member_attendance = '" . $percent_of_raids . "' WHERE member_name = '" . {$row['member_name']} . "'") or die (mysql_error());

 

side note:  Try debugging sql statements by using the or die (mysql_error()); at the end.  I bet if you put this at the end of your current query it will throw an error...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.