jack bro Posted March 29, 2009 Share Posted March 29, 2009 First of all I would like to say hello as this is my first post! I have a maffia game and you can own the Blackjack game this is the script for claiming the game. elseif ($grab == "Blackjack"){ $check = mysql_query("SELECT * FROM bj WHERE bjowner= '0' AND location='$fetch->location'"); $num_rows = mysql_num_rows($check); if ($num_rows != "0"){ if ($fetch->location == $location){ mysql_query("UPDATE bj SET bjowner='$username',bjmaxbet='0',bjearni... WHERE location='$fetch->location'"); echo "You got the Blackjack!"; It won't let me have the Blackjack game for some reason, the MYSQL table is: -- Table structure for table `bj` -- CREATE TABLE `bj` ( `id` int(11) NOT NULL auto_increment, `bjowner` varchar(100) NOT NULL default '', `bjmaxbet` int(100) NOT NULL default '0', `bjearnings` int(100) NOT NULL default '0', `bjminbet` int(100) NOT NULL default '0', `location` enum('England','Japan','Colombia','Usa',... Africa','Mexico') NOT NULL default 'England', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ; -- -- Dumping data for table `bj` -- Any help is apprechiated., when I click buy blackjack nothing happens. Jack. Quote Link to comment https://forums.phpfreaks.com/topic/151654-why-wont-this-work/ Share on other sites More sharing options...
jack bro Posted March 29, 2009 Author Share Posted March 29, 2009 CREATE TABLE `bj` ( `id` int(11) NOT NULL auto_increment, `bjowner` varchar(100) NOT NULL default '', `bjmaxbet` int(100) NOT NULL default '0', `bjearnings` int(100) NOT NULL default '0', `bjminbet` int(100) NOT NULL default '0', `location` enum('England','Japan','Colombia','Usa','South Africa','Mexico') NOT NULL default 'England', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ; Thats the SQL Quote Link to comment https://forums.phpfreaks.com/topic/151654-why-wont-this-work/#findComment-796413 Share on other sites More sharing options...
Maq Posted March 30, 2009 Share Posted March 30, 2009 Let's try and debug. Have you echoed out your variables to ensure they hold the correct/expected values? Your SQL may also be invalid. Change the msyql lines to: mysql_query("UPDATE bj SET bjowner='$username',bjmaxbet='0',bjearni... WHERE location='$fetch->location'") or die(mysql_error()); NOTE - Please use tags when posting code. Quote Link to comment https://forums.phpfreaks.com/topic/151654-why-wont-this-work/#findComment-796555 Share on other sites More sharing options...
jack bro Posted March 30, 2009 Author Share Posted March 30, 2009 I replaced the code and still nothing. What code can I use to echo the variables? And the full code is: elseif ($grab == "Blackjack"){ $check = mysql_query("SELECT * FROM bj WHERE bjowner= '0' AND location='$fetch->location'"); $num_rows = mysql_num_rows($check); if ($num_rows != "0"){ if ($fetch->location == $location){ mysql_query("UPDATE bj SET bjowner='$username',bjmaxbet='0',bjearnings='0',bjminbet='0' WHERE location='$fetch->location'"); echo "You got the Blackjack!"; }}} Thanks, Jack. Quote Link to comment https://forums.phpfreaks.com/topic/151654-why-wont-this-work/#findComment-796827 Share on other sites More sharing options...
Maq Posted March 30, 2009 Share Posted March 30, 2009 When you compare strings it's case sensitive. That means if $grab doesn't have a starting capital B and the rest lower case, then the elseif statement will not be true. I cleaned up your code and inserted some debugging lines for you: echo " grab => " . $grab; elseif ($grab == "Blackjack"){ $check = mysql_query("SELECT * FROM bj WHERE bjowner= '0' AND location='$fetch->location'") or die(mysql_query()); $num_rows = mysql_num_rows($check); if ($num_rows != 0){ if ($fetch->location == $location){ mysql_query("UPDATE bj SET bjowner='$username',bjmaxbet='0',bjearnings='0',bjminbet='0' WHERE location='$fetch->location'") or die(mysql_error()); echo "You got the Blackjack!"; } } } Quote Link to comment https://forums.phpfreaks.com/topic/151654-why-wont-this-work/#findComment-796842 Share on other sites More sharing options...
jack bro Posted March 30, 2009 Author Share Posted March 30, 2009 Still doesn't work, I have many other of these things which work in the same php file, so I think it's the database. Jack. Quote Link to comment https://forums.phpfreaks.com/topic/151654-why-wont-this-work/#findComment-796912 Share on other sites More sharing options...
Maq Posted March 30, 2009 Share Posted March 30, 2009 Are you looking at what's being echoed out? What EXACTLY does $grab echo out. (be case sensitive) Quote Link to comment https://forums.phpfreaks.com/topic/151654-why-wont-this-work/#findComment-796918 Share on other sites More sharing options...
jack bro Posted March 30, 2009 Author Share Posted March 30, 2009 I'm sure its a database problem, there is a page where people can "Grab" the blackjack when they click grab this happens. First it checks to see if another user owns this item: <tr> <td class="TableArea">BlackJack</td> <td class="TableArea"><?php if (!$bj->bjowner){ echo "No owner-<a href='?grab=blackjack&location=$locations[$i]'><font color=red>Grab It</font></a>"; }else{ echo "<a href='profile.php?viewuser=$bj->bjowner'>$bj->bjowner</a>"; } ?></td> <td class="TableArea"><? echo "$".makecomma($bj->bjmaxbet).""; ?></td> </tr> If the item is not owned by another use the grab link is displayed. When the grab button is pressed it should trigger this: elseif ($grab == "blackjack"){ $check = mysql_query("SELECT * FROM bj WHERE bjowner= '0' AND location='$fetch->location'"); $num_rows = mysql_num_rows($check); if ($num_rows != "0"){ if ($fetch->location == $location){ mysql_query("UPDATE bj SET bjowner='$username', profit='0' WHERE location='$fetch->location'"); echo "You got the BlackJack!"; }}} Where it updates the database to make it that whatever user grabbed this now owns it. The table in the database related to this item is "bj" and it layed out like this: CREATE TABLE `bj` ( `id` int(11) NOT NULL auto_increment, `bjowner` varchar(100) NOT NULL default '', `bjmaxbet` int(100) NOT NULL default '0', `bjearnings` int(100) NOT NULL default '0', `bjminbet` int(100) NOT NULL default '0', `location` enum('England','Japan','Colombia','Usa','South Africa','Mexico') NOT NULL default 'England', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ; Hopefully this makes things clearer. Jack. Quote Link to comment https://forums.phpfreaks.com/topic/151654-why-wont-this-work/#findComment-797169 Share on other sites More sharing options...
Maq Posted March 30, 2009 Share Posted March 30, 2009 Before we proceed, you're assigning $grab = $_GET['grab']; before you do the ifelse, right? Quote Link to comment https://forums.phpfreaks.com/topic/151654-why-wont-this-work/#findComment-797175 Share on other sites More sharing options...
jack bro Posted March 30, 2009 Author Share Posted March 30, 2009 Yes. Quote Link to comment https://forums.phpfreaks.com/topic/151654-why-wont-this-work/#findComment-797236 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.