Ifa Posted August 28, 2006 Share Posted August 28, 2006 $var = 1;mysql_query("UPDATE table SET var=var+'$var' FROM somewhere");For some reason only Internet Explorer makes the math correct, other browsers always return a bit higher number than they should (ie 1+1 = 5). I'm quite lost... Quote Link to comment Share on other sites More sharing options...
obsidian Posted August 28, 2006 Share Posted August 28, 2006 try it without the single quotes, since you're dealing with adding integers. as for the difference between browsers, that doesn't make much sense to me, since the math is being handled by the server. is the variable being populated from a form field, or when you run the code just as you have it, is it off? next question: why do you have a FROM clause in an update statment? what are you trying to do? shouldn't it be a WHERE?[code]<?php$var = 1;mysql_query("UPDATE tableName SET var = var + $var WHERE something = something");?>[/code] Quote Link to comment Share on other sites More sharing options...
Ifa Posted August 28, 2006 Author Share Posted August 28, 2006 Oops, your right about the from, I use where, I just wrote the code as an example and made a tiny mistake :)No, the data isn't coming from a form, it's a number that is increased in a loop. But thanks, I'll try it without no single quotes. I can test it now though, as I'm at work, and all this comp has is IE...To be more spesific, the number is a calculation actually, $var = round($var2 / $var3, 0); Quote Link to comment Share on other sites More sharing options...
fenway Posted August 28, 2006 Share Posted August 28, 2006 This can't have anything to do with the browser or MySQL... it's a PHP issue. Quote Link to comment Share on other sites More sharing options...
Ifa Posted August 29, 2006 Author Share Posted August 29, 2006 This is getting funny:$var = $var2 + 10;mysql_query("UPDATE table SET var = $var WHERE some=thing ") or die('Query failed: ' . mysql_error());echo $var;the echo returns 16, but the update makes it 18... And though it seems extremely odd, IE just makes it right, and firefox doesn't. So much for it being a serverside language ;)$var2 = -1 * round(($var3 * $var4) / $var5, 0);Oh and with or without ' ' seems to make no diffrence... Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 29, 2006 Share Posted August 29, 2006 I agree with Fenway. Quote Link to comment Share on other sites More sharing options...
fenway Posted August 29, 2006 Share Posted August 29, 2006 Well, at least in theory, you're not locking your tables, so you could have a race condition somewhere. Quote Link to comment Share on other sites More sharing options...
Ifa Posted August 31, 2006 Author Share Posted August 31, 2006 I'm somewhat new to mysql, what do you mean by locked? Quote Link to comment Share on other sites More sharing options...
fenway Posted August 31, 2006 Share Posted August 31, 2006 There can be a concurrency issue with non-transaction safe statements. Quote Link to comment Share on other sites More sharing options...
Ifa Posted August 31, 2006 Author Share Posted August 31, 2006 Ah, that makes sense :) 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.