voxxtelum Posted February 23, 2008 Share Posted February 23, 2008 Hey is it possible to update a row where the column I want to update changes. For example $update_user_part = mysql_query("update user_parts set '$new_part_id' = 1 where userid = '$user_id'"); I tried that and it is not working and the only thing that I could narrow it down to was the variable. Is there a way I can do this using a variable? The only solution I can think of is setting up a switch case and running a different update for each one. Is there a more efficient way to do this? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted February 23, 2008 Share Posted February 23, 2008 what is 'not working?' are there any errors? you may want to die(mysql_error()) to find out: $sql = "update user_parts set '$new_part_id' = 1 where userid = '$user_id'"; $update_user_part = mysql_query($sql) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Bauer418 Posted February 23, 2008 Share Posted February 23, 2008 <?php $new_part_id = 'mycolumn'; $update_user_part = mysql_query("UPDATE user_parts SET `" . $new_part_id . "`='1' WHERE userid='" . $user_id . "'") or die(mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted February 23, 2008 Share Posted February 23, 2008 Don't put a single quote around 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.