Michdd Posted October 19, 2008 Share Posted October 19, 2008 I'm using this as an UPDATE function: $result = mysql_query("UPDATE monsters SET $updatewhat='$updateto' WHERE $updatewhat='$where'") or die(mysql_error()); But I want to make that $updatewhat='$where' also be WHERE $updatewhat='$updatemon' So in theory it would be: $result = mysql_query("UPDATE monsters SET $updatewhat='$updateto' WHERE $updatewhat='$where' WHERE $updatewhat='$updatemon'") or die(mysql_error()); However, that's incorrect syntax. Quote Link to comment Share on other sites More sharing options...
Twister1004 Posted October 19, 2008 Share Posted October 19, 2008 The reason why, is because your setting to to a variable. so say we used $updatewhat as paper and $updateto as ink and $where as blood. This is what your statement would do: $result = mysql_query("UPDATE monsters SET $updatewhat="ink" WHERE $updatewhat="blood" ") You never told SQL to define the variables. Try this (Note i did not test this.) $result = mysql_query("UPDATE monsters SET '$updatewhat' = '$updateto' WHERE '$updatewhat' = '$where'") or die(mysql_error()); However, I still think the SET $updatewhat should be defined and not a variable. True you might have to add in more code, but it would be less confusing and easier to change. Quote Link to comment Share on other sites More sharing options...
Michdd Posted October 19, 2008 Author Share Posted October 19, 2008 The reason why, is because your setting to to a variable. so say we used $updatewhat as paper and $updateto as ink and $where as blood. This is what your statement would do: $result = mysql_query("UPDATE monsters SET $updatewhat="ink" WHERE $updatewhat="blood" ") You never told SQL to define the variables. Try this (Note i did not test this.) $result = mysql_query("UPDATE monsters SET '$updatewhat' = '$updateto' WHERE '$updatewhat' = '$where'") or die(mysql_error()); However, I still think the SET $updatewhat should be defined and not a variable. True you might have to add in more code, but it would be less confusing and easier to change. You see, the problem is that it will then change all the fields that are $where. I want it to only update the one field in the 1 row that is shown as $updatemon Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 20, 2008 Share Posted October 20, 2008 $updatewhat can't be $where AND $updatemon in the same row. Can you explain what you really want to do? Maybe you meant OR rather than AND 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.