Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 07-11-2009, 05:41 AM
Quillink Quillink is offline
Member
 
Join Date: Dec 2008
Posts: 93
Credits: 11,285
Quillink
Lightbulb MySQL queries ..?

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.
Reply With Quote
  #2  
Old 07-11-2009, 09:12 AM
Seapyramid Seapyramid is offline
Premium Member
 
Join Date: Feb 2009
Posts: 373
Gender: Female
Credits: 15,572
Seapyramid
Default RE: MySQL queries ..?

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
Reply With Quote
  #3  
Old 07-11-2009, 11:37 AM
BMR777 BMR777 is offline
Member
 
Join Date: Jan 2011
Posts: 1,122
Gender: Male
Credits: 10,706
BMR777 is on a distinguished road
Default RE: MySQL queries ..?

This may be the issue:

PHP Code:
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 Code:
mysql_query("UPDATE users SET clix = '".$newclix."' WHERE username = '$loggedinname'"); 
Should probably be:

PHP Code:
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
Reply With Quote
  #4  
Old 07-11-2009, 11:47 AM
Quillink Quillink is offline
Member
 
Join Date: Dec 2008
Posts: 93
Credits: 11,285
Quillink
Default RE: MySQL queries ..?

Works great, thanks Brandon. :)
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Troubles with queries pachoofoosh Questions and Supports 4 08-05-2013 11:32 AM
Question about Queries? Tsuntsun Questions and Supports 2 11-03-2011 01:57 PM
MySQL: What to do? Knyfe Questions and Supports 18 03-11-2011 12:52 PM
Anyone care to enlighten me as to why 188 queries are used on a page? Arianna Questions and Supports 5 05-14-2010 09:21 AM
mySQL help aroymart Questions and Supports 4 04-20-2009 12:13 AM


All times are GMT -5. The time now is 05:50 AM.

Currently Active Users: 9807 (0 members and 9807 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636