View Single Post
  #3  
Old 03-26-2009, 03:13 PM
kisazeky kisazeky is offline
Member
 
Join Date: Mar 2009
Posts: 44
Credits: 19,401
kisazeky
Default RE: How to "buy" adoptables?

Quote:
Originally Posted by BMR777
You would have to get the info from both tables and store in variables. Then check if the money variable is greater than or equal to the currency in the users table. If it is, then deduct the currency and do the transaction. :)
Yeah I tried to do that, but I can't get the code to replace the "name the adoptable" article content with "you can't afford this adoptable" if they don't have enough money.

It takes me to the name the adoptable page even if I in fact have less money than the adoptable cost.

This is the code I'm using:

PHP Code:
}
else if (
$isloggedin == "yes" and $aID != ""){
//A Logged In user is adopting a new creature

//Check first that the creature does in fact exist...
//Get adoptable info
$query "SELECT * FROM adoptables WHERE uid = '$aID'";
$result = @mysql_query($query);
$num = @mysql_numrows($result);

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

$newID=@mysql_result($result,$i,"uid");
$name=@mysql_result($result,$i,"name");
$imageurl=@mysql_result($result,$i,"imageurl");
$cost=@mysql_result($result,$i,"description");

$i++;
}
//Get how much money you have
$query "SELECT * FROM `users` WHERE `username` = '$username'";
$result mysql_query($query);
$num mysql_numrows($result);

//Loop out code
$i=0;
    while (
$i 1) {
    
    
$money =@mysql_result($result,$i,"money");
    
$i++;
    }

if(
$newID != $aID){
$stop 1;
$article_title "Error";
$article_date date('Y-m-d');
$article_content "This Digimon is not available for adoption. <a href='adopt.php'>Go back</a>.";
}

//Can the user afford the adoptable?
if($money $cost){
$article_title "Oops";
$article_date date('Y-m-d');
$article_content "You can't afford this Digimon.";
}

else {
//Creature is valid, let's adopt the sucker...
//Procedure for giving the user's adoptable a name

    
if($cname == "" and $flag !=12){
    
$article_title "Adopt ".$name;
    
$article_date date('Y-m-d');
    
$article_content "<p align='left'>You are about to adopt ".$name.". </p>
<p align='left'><img src='"
.$imageurl."' border='0'></a> </p>
<p align='left'>You may give your new Digimon a nickname.  His or her name can contain letters, numbers and spaces.</p>
<form name='form1' method='get' action='adopt.php'>
  <p>
    <input name='aID' type='hidden' id='aID' value = '"
.$aID."'>
    Nickname 
    <input name='cname' type='text' id='cname' size=20 maxlength='20'>
    <input name='flag' type='hidden' id='flag' value = '12'>
  </p>
  <p>
    <input type='submit' name='Submit' value='Adopt!'>
</p>
</form>"
;
    }
    }
    }

    else{ 
Here are what the tables being referenced look like:





What is the problem?
Reply With Quote