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."; } ?> Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/ 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 Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224123 Share on other sites More sharing options...
grlayouts Posted April 8, 2007 Author Share Posted April 8, 2007 ??? Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224128 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 Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224131 Share on other sites More sharing options...
grlayouts Posted April 8, 2007 Author Share Posted April 8, 2007 nah not working still.. Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224132 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????? Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224134 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 ? Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224137 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 Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224142 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. Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224147 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 Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224152 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.. Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224155 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 Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224156 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. Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224158 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 Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224161 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. Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224209 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. Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224213 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 Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224253 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. Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224254 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. Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224257 Share on other sites More sharing options...
grlayouts Posted April 8, 2007 Author Share Posted April 8, 2007 ??? so...?? LOL! Link to comment https://forums.phpfreaks.com/topic/46123-not-updating/#findComment-224259 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.