MySQL queries ..?

Forum
Last Post
Threads / Messages

Quillink

Member
Member
Joined
Dec 18, 2008
Messages
93
Points
0
Mysidian Dollar
7,188
I've recently constructed my own store and currency system from scratch, with the help from a few tutorials and careful examination of Brandon's script of course. I've gotten as far as the currency, store and store adoption process - heck, everything's working except one tiny simple thing: updating the user's money once s/he buys something!

I even went as far as examining the old easyadopts store mod to see how they did it, then duplicated it, and still nothing? I'm certain it's something simple, perhaps the placement of the code or a missing quotation mark, but here it is:

Code:
else{

// The adoptable ID appears to be valid, so we need to double check that it is valid by pulling up the adoptable in the DB

$query = "SELECT * FROM ".$prefix."store WHERE id='$id'";
$result = mysql_query($query);
$num = mysql_numrows($result);

//Loop out code
$i=0;
while ($i < 1) {

$aid=@mysql_result($result,$i,"id"); //The adoptable's ID
$type=@mysql_result($result,$i,"name");
$description=@mysql_result($result,$i,"description");
$eggimage=@mysql_result($result,$i,"eggimage");
$clixprice=@mysql_result($result,$i,"clixprice");
$cashprice=@mysql_result($result,$i,"cashprice");

$query2 = "SELECT * FROM ".$prefix."users WHERE username='$loggedinname'";
$result2 = mysql_query($query2);
$num2 = mysql_numrows($result2);
$clix=@mysql_result($result2,$i,"clix");
$cash=@mysql_result($result2,$i,"cash");


if($_GET["payclix"])
{ $newclix = $clix - $clixprice;
mysql_query("UPDATE users SET clix = '".$newclix."' WHERE username = '$loggedinname'");
$i++;
echo "clix: $clix balance: $newclix price: $clixprice name: $loggedinname";
}

elseif($_GET["paycash"])
{ $newcash = $cash - $cashprice;
mysql_query("UPDATE users SET cash = '".$newcash."' WHERE username = '$loggedinname'");
$i++;
echo "cash: $cash balance: $newcash price: $cashprice name: $loggedinname";
}


$i++;
}

This is from a duplicated, modified version of 'doadopt.php', and I know the scripting is very nooby, I just picked it up over the past two weeks. Please point out any other problems if you see them! ;)

Unfortunately you won't see it uploaded as a mod for two reasons:
1) It's very Arvyre-specific
2) There are so many small changes to the script I couldn't possibly deconstruct it..! Sorry.
 
This is the query I am using and it works great.

Code:
      $query = "SELECT * FROM `adopts_users` WHERE `username`='$loggedinname'";
      $result = mysql_query($query);
      $num = mysql_numrows($result);
      
      $i = 0;
      while ($i < $num) {
          $money = @mysql_result($result, $i, "money");
           $newbalance = $money - $cost;
          $i++;
      }
      mysql_query("UPDATE `adopts_users` SET `money`='" . $newbalance . "' WHERE `username`='$loggedinname'");
Sea
 
This may be the issue:

PHP:
if($_GET["payclix"])
{ $newclix = $clix - $clixprice;
mysql_query("UPDATE users SET clix = '".$newclix."' WHERE username = '$loggedinname'");
$i++;
echo "clix: $clix balance: $newclix price: $clixprice name: $loggedinname";
}

elseif($_GET["paycash"])
{ $newcash = $cash - $cashprice;
mysql_query("UPDATE users SET cash = '".$newcash."' WHERE username = '$loggedinname'");
$i++;
echo "cash: $cash balance: $newcash price: $cashprice name: $loggedinname";
}

Mainly lines such as:

PHP:
mysql_query("UPDATE users SET clix = '".$newclix."' WHERE username = '$loggedinname'");

Should probably be:

PHP:
mysql_query("UPDATE ".$prefix."users SET clix = '".$newclix."' WHERE username = '$loggedinname'");

It simply looks like in a few of your queries you may be forgetting to use the table prefix for your database tables. :)

Let me know if that helps,
Brandon
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,278
Messages
33,127
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top