grlayouts Posted April 8, 2007 Share Posted April 8, 2007 my code should update the cash and drugs of a player when he sells but its not working. <?php print "<form method=post action=enterprises.php?view=add&step=add>Sell <input name=amount><select name=seller><option value=Drugs>Drugs</option></select>. <input type=submit value=Sell></form>"; if ($step == "Sell") { switch($seller) { case "Drugs": if ($stat[drugs] < $amount) { print "Sorry mate, you don't have the drugs."; } else { mysql_query("update players set drugs=drugs-$amount where id=$stat[id]"); mysql_query("update players set credits=$amount*$stat[drugprice] where id=$stat[id]"); print "You sold $amount of drugs."; } ?> Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 ok, well instead of gooing: ";skdjfghlskdjfhg $VARIABLE fkdghsldfkjghslkjdfgh" use "aksjdfhalkjgh".$VARIABLE.",khdgksjdghkjagf"; also, do you have to include the database connection variable for the query, i use mysqli and that requires it??? if that doesnt work. where you have a calculation, actually store the result of the calculation in another variable and use that variable for the string. good luck Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 8, 2007 Author Share Posted April 8, 2007 ??? Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 if its about the string stuff, soz i dont blame you instead of going "UPDATE players SET blah blah blah = $variable", use: "UPDATE players SET blah blah blah = ".$variable; good luck Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 8, 2007 Author Share Posted April 8, 2007 nah not working still.. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 did you do the new variables for the calculation s????? Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 8, 2007 Author Share Posted April 8, 2007 ie? $hello = $stat[1] + $stat[2] update blah=blah+$hello ? Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 $hello = $stat[1] + $stat[2]; $SQL = "update blah=blah+".$hello; $query = mysql_query($SQL) or die("query didnt work!!!") that should get you something Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 8, 2007 Author Share Posted April 8, 2007 no idea how to fit that in. its just messing up now. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 that structure should replace your general query structure Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 8, 2007 Author Share Posted April 8, 2007 yeah i know what it should do, but now ive replaced it its doing nothing.. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 ok, cut the or die, and simply do mysql_query($sql); see what that returns Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 8, 2007 Author Share Posted April 8, 2007 nothing just reverts back and doesnt update anything. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 paste this code into the bottome of your page, as the very last line before the end tag itll display every variable, array in the entire page, even the globals that you dont set youll get whatever output the page gives, then this long list. also, stor the querys in variable ie $var1 = mysql_query() etc. then look for the $var1 in the long list and place value here if the value is mysql_result_object, or somethig similar, then store another 4 variables $result1 and 2, and for each go $result1 = mysql_fetch_array($query1variable); then look for these new variables and paste them herein the forum this will tell us whether of not the query is returning anything..... good luck Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 8, 2007 Author Share Posted April 8, 2007 so ive changed everything and now im getting nought? and my code is sooo messy now. Quote Link to comment Share on other sites More sharing options...
per1os Posted April 8, 2007 Share Posted April 8, 2007 <?php print "<form method=post action=enterprises.php?view=add&step=add>Sell <input name=amount><select name=seller><option value=Drugs>Drugs</option></select>. <input type=submit value=Sell></form>"; if ($step == "Sell") { switch($seller) { case "Drugs": if ($stat['drugs'] < $amount) { print "Sorry mate, you don't have the drugs."; } else { mysql_query("update players set drugs=(drugs-$amount) where id=".$stat[id]) OR DIE(mysql_error()); mysql_query("update players set credits=($amount*".$stat['drugprice'].") where id=".$stat['id']) DIE(mysql_error()); print "You sold $amount of drugs."; } ?> Try that out. Sometimes calling from arrays, especially like the index is a constant does weird stuff. Also added parans as they are generally a good idea when doing ANY type of math function. If that still does not work report back the error. Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 8, 2007 Author Share Posted April 8, 2007 Parse error: syntax error, unexpected T_EXIT in /home/hoboempi/public_html/cmarket.php on line 36 Quote Link to comment Share on other sites More sharing options...
per1os Posted April 8, 2007 Share Posted April 8, 2007 <?php print "<form method=post action=enterprises.php?view=add&step=add>Sell <input name=amount><select name=seller><option value=Drugs>Drugs</option></select>. <input type=submit value=Sell></form>"; if ($step == "Sell") { switch($seller) { case "Drugs": if ($stat['drugs'] < $amount) { print "Sorry mate, you don't have the drugs."; } else { mysql_query("update players set drugs=(drugs-$amount) where id=".$stat[id]) OR DIE(mysql_error()); mysql_query("update players set credits=($amount*".$stat['drugprice'].") where id=".$stat['id']) DIE(mysql_error()); print "You sold $amount of drugs."; } break; } ?> I would of hopped you could of fixed the syntax, guess I was wrong. Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 8, 2007 Author Share Posted April 8, 2007 sorry. i'm really new at php. Quote Link to comment Share on other sites More sharing options...
grlayouts Posted April 8, 2007 Author Share Posted April 8, 2007 ??? so...?? LOL! 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.