grlayouts Posted March 3, 2007 Share Posted March 3, 2007 The script below should insert into the database one factory on the drop down as long as the player has cash. However its only working on the drug one not the steak house. any idea's? <? print "<form method=post action=enterprises.php?view=add&step=add>Build <select name=building><option value=DrugFactory>Drug Factory</option><option value=SteakHouse>Steak House</option><option value=CarLot>Car Lot</option><option value=Passport>Passport</option></select>. <input type=submit value=Add></form>"; if ($step == add) { if ($building == 'DrugFactory') { if ($stat[credits] <30000) { print "Sorry mate, you don't have the cash."; } else { mysql_query("update players set drugfact=drugfact+1 where id=$stat[id]"); print "Building added."; }}} else { if ($building == '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]"); print "Building added."; }}}?> Link to comment https://forums.phpfreaks.com/topic/41033-solved-only-adding-one/ Share on other sites More sharing options...
JBS103 Posted March 3, 2007 Share Posted March 3, 2007 What should $step equal when you want to add a steakhouse? Is the program outputting anything when you try to make a new steakhouse? Link to comment https://forums.phpfreaks.com/topic/41033-solved-only-adding-one/#findComment-198694 Share on other sites More sharing options...
grlayouts Posted March 3, 2007 Author Share Posted March 3, 2007 what? Link to comment https://forums.phpfreaks.com/topic/41033-solved-only-adding-one/#findComment-198695 Share on other sites More sharing options...
JBS103 Posted March 3, 2007 Share Posted March 3, 2007 Does the screen show either "Sorry mate, you don't have the cash." or "Building added." when you try to make a steak house, or is the screen blank? Link to comment https://forums.phpfreaks.com/topic/41033-solved-only-adding-one/#findComment-198698 Share on other sites More sharing options...
LazyJones Posted March 3, 2007 Share Posted March 3, 2007 Your statements (opening and closing curly brackets) are a bit messed up: that code will never enter to checking for 'steakhouse' if the $step == 'add' btw. using e.g. switch-case statement would be cleaner and you would better avoid errors like such Link to comment https://forums.phpfreaks.com/topic/41033-solved-only-adding-one/#findComment-198701 Share on other sites More sharing options...
grlayouts Posted March 3, 2007 Author Share Posted March 3, 2007 Does the screen show either "Sorry mate, you don't have the cash." or "Building added." when you try to make a steak house, or is the screen blank? i get nothing.. what would you suggest? Link to comment https://forums.phpfreaks.com/topic/41033-solved-only-adding-one/#findComment-198703 Share on other sites More sharing options...
JBS103 Posted March 3, 2007 Share Posted March 3, 2007 Does the screen show either "Sorry mate, you don't have the cash." or "Building added." when you try to make a steak house, or is the screen blank? i get nothing.. what would you suggest? What LazyJones suggested seems right. Thats why I asked what you expected the $step variable to equal when you wanted to add a steakhouse, because he is right, it will never get down there if $step == add Link to comment https://forums.phpfreaks.com/topic/41033-solved-only-adding-one/#findComment-198704 Share on other sites More sharing options...
grlayouts Posted March 3, 2007 Author Share Posted March 3, 2007 ermm ok, i still have no idea how to do it. Link to comment https://forums.phpfreaks.com/topic/41033-solved-only-adding-one/#findComment-198706 Share on other sites More sharing options...
JBS103 Posted March 3, 2007 Share Posted March 3, 2007 <?php print "<form method=post action=enterprises.php?view=add&step=add>Build <select name=building><option value=DrugFactory>Drug Factory</option><option value=SteakHouse>Steak House</option><option value=CarLot>Car Lot</option><option value=Passport>Passport</option></select>. <input type=submit value=Add></form>"; if ($step == "add") { switch($building) { case "DrugFactory": if ($stat[credits] < 30000) { print "Sorry mate, you don't have the cash."; } else { mysql_query("update players set drugfact=drugfact+1 where id=$stat[id]"); print "Building added."; } 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]"); print "Building added."; } break; } } ?> Try something like that Link to comment https://forums.phpfreaks.com/topic/41033-solved-only-adding-one/#findComment-198712 Share on other sites More sharing options...
grlayouts Posted March 3, 2007 Author Share Posted March 3, 2007 perfect. your the man. Link to comment https://forums.phpfreaks.com/topic/41033-solved-only-adding-one/#findComment-198717 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.