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? Link to comment https://forums.phpfreaks.com/topic/92621-mysql-update-help/ 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()); Link to comment https://forums.phpfreaks.com/topic/92621-mysql-update-help/#findComment-474707 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()); ?> Link to comment https://forums.phpfreaks.com/topic/92621-mysql-update-help/#findComment-474708 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 Link to comment https://forums.phpfreaks.com/topic/92621-mysql-update-help/#findComment-474784 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.