grlayouts Posted April 10, 2007 Share Posted April 10, 2007 when i hit sell 400 drugs it does nothing updates nothing and doesnt print anything. can anyone suggest a better way to do it or fix it? <?php print "<form method=post action=cmarket.php?view=sell&step=sell>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."; } break; case "SteakHouse": if ($stat[credits] < 60000) { print "Sorry mate, you don't have the cash."; } else { mysql_query("update players set steakhouse=steakhouse+1 where id=$stat[id]"); mysql_query("update players set credits=credits-60000 where id=$stat[id]"); mysql_query("update players set employees=employees+10 where id=$stat[id]"); print "Steak Building added."; } break; } } ?> Link to comment https://forums.phpfreaks.com/topic/46471-solved-ammounts/ Share on other sites More sharing options...
lead2gold Posted April 10, 2007 Share Posted April 10, 2007 Your not using your variables properly... Since the form is set up as type post, you should be accessing the $_POST variable to get your information. $seller should become => $_POST['seller'] $step should become => $_POST['step'] etc... Try flipping your variable names around first and see if your still having problems. Link to comment https://forums.phpfreaks.com/topic/46471-solved-ammounts/#findComment-226093 Share on other sites More sharing options...
grlayouts Posted April 10, 2007 Author Share Posted April 10, 2007 <?php print "<form method=post action=cmarket.php?view=sell&step=sell>Sell <input name=amount><select name=seller><option value=drugs>Drugs</option></select>. <input type=submit value=Sell></form>"; if ($_POST['step'] == "sell") { switch($_POST['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."; } still getting nothing? Link to comment https://forums.phpfreaks.com/topic/46471-solved-ammounts/#findComment-226102 Share on other sites More sharing options...
boo_lolly Posted April 10, 2007 Share Posted April 10, 2007 something like: <?php print "<form method=post action=cmarket.php?view=sell&step=sell>Sell <input name=amount><select name=seller><option value=drugs>Drugs</option></select>. <input type=submit value=Sell></form>"; if (isset($_POST)){ switch($_POST['seller']) { case $_POST['seller']: 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."; } break; } } ?> Link to comment https://forums.phpfreaks.com/topic/46471-solved-ammounts/#findComment-226133 Share on other sites More sharing options...
grlayouts Posted April 10, 2007 Author Share Posted April 10, 2007 sorry, where is that specifying drugs because i will be adding more? Link to comment https://forums.phpfreaks.com/topic/46471-solved-ammounts/#findComment-226135 Share on other sites More sharing options...
grlayouts Posted April 10, 2007 Author Share Posted April 10, 2007 sorry, where is that specifying drugs because i will be adding more? Link to comment https://forums.phpfreaks.com/topic/46471-solved-ammounts/#findComment-226143 Share on other sites More sharing options...
boo_lolly Posted April 10, 2007 Share Posted April 10, 2007 give a little more information on what you are trying to do. my code simply shows that you don't have to have a hundred cases for your switch statment. you can alternatively have the switch case change dynamically, as will the functions executed for each case. what is $stat and where is it coming from? Link to comment https://forums.phpfreaks.com/topic/46471-solved-ammounts/#findComment-226163 Share on other sites More sharing options...
grlayouts Posted April 10, 2007 Author Share Posted April 10, 2007 sorry.. $stat was from the header that got * from players, fixed it but thank you very much. Link to comment https://forums.phpfreaks.com/topic/46471-solved-ammounts/#findComment-226177 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.