Jump to content

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...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.