Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/151654-why-wont-this-work/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/151654-why-wont-this-work/#findComment-796413
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/151654-why-wont-this-work/#findComment-796555
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/151654-why-wont-this-work/#findComment-796827
Share on other sites

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!";
      }
   } 
}

Link to comment
https://forums.phpfreaks.com/topic/151654-why-wont-this-work/#findComment-796842
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/151654-why-wont-this-work/#findComment-797169
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.