almightyegg Posted April 14, 2009 Share Posted April 14, 2009 I have this code that just won't insert the right values, yet there is no error message.... if($defender[id] != $mem[last1] && $defender[id] != $mem[last2] && $defender[id] != $mem[last3] && $defender[id] != $mem[last4] && $defender[id] != $mem[last5]){ $new1 = $defender[id]; $new2 = $mem[last1]; $new3 = $mem[last2]; $new4 = $mem[last3]; $new5 = $mem[last4]; $up = mysql_query("UPDATE users SET last1 = '$new1' and last2 = '$new2' and last3 = '$new3' and last4 = '$new4' and last5 = '$new5' WHERE id = '{$mem['id']}'") or die(mysql_error()); if(!$up){ echo "ERRORZ"; } } The first time I run this code it updates with $mem[id] instead of $defender[id] into $new1 so values are thus: $new1 = 1; $new2 = 0; $new3 = 0; $new4 = 0; $new5 = 0; But just before the SQL I echo them out they are correct ($new1 = 2;) What's more if I run it again, all the values become 0 in the SQL when they should still be $new1 = 2; $new2 = 0; $new3 = 0; $new4 = 0; $new5 = 0; or if I changed the $defender[id] it should be $new1 = newid; $new2 = 2; $new3 = 0; $new4 = 0; $new5 = 0; but it still inserts as 0 for all 5 values! I'm so so confused..... Link to comment https://forums.phpfreaks.com/topic/154045-solved-so-confused/ Share on other sites More sharing options...
ober Posted April 14, 2009 Share Posted April 14, 2009 You can't do "AND" in an insert. $sql = "UPDATE tablexyz SET value1 = '$x', value2 = '$y' WHERE id = '{$mem['id']}' or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/154045-solved-so-confused/#findComment-809758 Share on other sites More sharing options...
almightyegg Posted April 14, 2009 Author Share Posted April 14, 2009 it's an update Link to comment https://forums.phpfreaks.com/topic/154045-solved-so-confused/#findComment-809772 Share on other sites More sharing options...
ober Posted April 14, 2009 Share Posted April 14, 2009 Sorry, I meant to put UPDATE, not INSERT. My syntax is correct otherwise... see corrections above. Link to comment https://forums.phpfreaks.com/topic/154045-solved-so-confused/#findComment-809791 Share on other sites More sharing options...
almightyegg Posted April 14, 2009 Author Share Posted April 14, 2009 I swear I never use that syntax. Oops. Cheers, works a treat Link to comment https://forums.phpfreaks.com/topic/154045-solved-so-confused/#findComment-809825 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.