XJTRy Posted February 5, 2009 Share Posted February 5, 2009 I am trying to use the below query to update a value in the table. Essentially, I'm asking if the user submitted the correct answer to a question (in this case, "b"). If the user submitted the correct answer he is awarded a point value ($pointValue) in his row's total column. Here is the query: $data = mysql_query("SELECT choice1 FROM members WHERE user = '$user'"); $info = mysql_fetch_array($data); if ($info[0] == "b"){ "UPDATE members SET total = '$pointValue' WHERE user = '$user'"; } I have used the same query and if statement, but made the conditionals: print "You have chosen the correct answer" else print "You have chosen the incorrect answer" and that worked just fine. The data is being added to the array correctly, but the if statement above is not updating the table. Thanks for any help! Link to comment https://forums.phpfreaks.com/topic/143856-mysql-query-to-update-table/ Share on other sites More sharing options...
gevans Posted February 5, 2009 Share Posted February 5, 2009 if ($info[0] == "b"){ "UPDATE members SET total = '$pointValue' WHERE user = '$user'"; } doesn't do anything, you need to run the query; $query = "UPDATE members SET total = '$pointValue' WHERE user = '$user'"; $result = mysql_query($query) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/143856-mysql-query-to-update-table/#findComment-754882 Share on other sites More sharing options...
XJTRy Posted February 5, 2009 Author Share Posted February 5, 2009 I have tried that as well. The following still doesn't do the trick: $data = mysql_query("SELECT choice1 FROM members WHERE user = '$user'"); $info = mysql_fetch_row($data); if ($info[0] == "b"){ $query = "UPDATE members SET total = '$pointValue' WHERE user = '$user'"; $result = mysql_query($query) or die(mysql_error()); } Link to comment https://forums.phpfreaks.com/topic/143856-mysql-query-to-update-table/#findComment-754979 Share on other sites More sharing options...
XJTRy Posted February 5, 2009 Author Share Posted February 5, 2009 Got it. For some reason the local variable '$pointValue' will not update the table. I had to use SET total = pointValue(column name). I'm assuming the local variable must be used in a sprintf(). Link to comment https://forums.phpfreaks.com/topic/143856-mysql-query-to-update-table/#findComment-754981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.