djax 0 Report post Posted September 20, 2005 if($s == "poed") ?{ ?if($c == "relva") ? { ? if($osta <= 4 && $osta > 0) ? ?{ ? ?$sql = "SELECT * FROM charinf WHERE nimi = $flgin"; ? ?$query = mysql_query($sql); ? ?while($q = mysql_fetch_array($query)) ? ? { ? ? $hraha = $q["raha"]; ? ? } ? ?if($hraha >= $relvahinnad[$osta]) ? ? { ? ? $sql = "INSERT INTO kott (omanik, aid, arv, kat) VALUES ($flgin , $osta , 1 , 1)"; ? ? mysql_query($sql); ? ? $jarraha = $hraha - $relvahinnad[$osta]; ? ? $sql = "UPDATE charinf SET raha = $jarraha WHERE nimi = $flgin"; ? ? mysql_query($sql); ? ? } ? ?} ? } ?} Share this post Link to post Share on other sites
dogomchawi 0 Report post Posted September 20, 2005 Without knowing the error that you were encountering I am going to give you my best explanation of what is wrong. I highlighted the lines with the problems on it below. $sql = "SELECT * FROM charinf WHERE nimi = $flgin"; $sql = "INSERT INTO kott (omanik, aid, arv, kat) VALUES ($flgin , $osta , 1 , 1)"; $sql = "UPDATE charinf SET raha = $jarraha WHERE nimi = $flgin"; Explanation:When you are working with "" in PHP/MySQL you need to remember that it will treat it as a literal string.What the code lines above are telling the MySQl to do is to compare two columns together - not the values of a variable in one of the columns ( i.e SELECT all from the charinf table where the table column nimi is equal to the table column with the name of the variable of $flgin). This is not what you are looking to do with this code. If you want to use variables in a MySQL statement within PHP you need to put it in single quotes (' ').Here is my proposed solution::if($s == "poed") { if($c == "relva") { if($osta <= 4 && $osta > 0) { $sql = "SELECT * FROM charinf WHERE nimi = '$flgin' "; $query = mysql_query($sql); while($q = mysql_fetch_array($query)) { $hraha = $q["raha"]; } if($hraha >= $relvahinnad[$osta]) { $sql = "INSERT INTO kott (omanik, aid, arv, kat) VALUES ('$flgin' , '$osta' , 1 , 1)"; mysql_query($sql); $jarraha = $hraha - $relvahinnad[$osta]; $sql = "UPDATE charinf SET raha = '$jarraha' WHERE nimi = '$flgin' "; mysql_query($sql); } } } } NOW - assuming that all your other syntax and stuff is right according to how u wrote the rest of tha page - the code above should work. If not then you would still have had that problem with the code anyways. Notice from snlildude87: Posts merged Share this post Link to post Share on other sites
beeseven 0 Report post Posted September 22, 2005 O_o unless they changed it recently (last 2 months or so), then variables are treated as their values only in double quotes, not singles. Ex: $x = 9;echo "$x";echo "<br>";echo '$x';should output 9$x Share this post Link to post Share on other sites
Spectre 0 Report post Posted September 23, 2005 That's what dogomchawi is saying. The entire query must be enclosed in double quotes, but field values must be enclosed in single quotes within the double quotes (or it can work the other way, provided you specify either constant values or add them outside the quotes). MySQL requires that string-like values be enclosed in quotes to determine delimitation - numeric values are, obviously, only going to contain numbers (and possible a decimal place), whereas strings can contain spaces and any other number of 'special' characters which MySQL may mistake as indicating it should move to the next field assignment.I hope that makes sense. Oh, and you should -always- use single quotes where possible. Strings contained within single quotes are not checked for variable references etc, so they are processed much more quickly (even if a string contained within double quotes doesn't contain any variable names at all, it is still checked for them as well as other escaped characters, which takes processing power and time). Share this post Link to post Share on other sites
magiccode9 0 Report post Posted November 2, 2005 hi, all, I have go through all the code above, yes, that should be careful. If not, would produces a long time debug action. furthermore, I checked that the code have only use only single field of the table, but that select all fields of that, this should make the mysql server generate more data and activity, as many programmer experts said, avoid any unneeded data. That will make server service more client and lower the tco.- hope this help- Eric Share this post Link to post Share on other sites