Multi-cash integration

Forum
Last Post
Threads / Messages

PTGigi

Crazily Friendly~HoF
Premium Member
Joined
Jul 17, 2009
Messages
363
Points
0
Age
29
Location
Somewhere >.>
Mysidian Dollar
15,125
So for my site I have 6 different cash types. And the Mysidia base only has 1. So when I went to merge my site with the new Mysidia release (or one of those releases which had cash) everything worked fine except for adopting pets.

It goes through the whole "here's you pet, name it, and oh look here's your new adoptable" thing but when I get to the "Congrats you've adopted ____" page and click on the 'levelup' link it says I have an invalid adoptable id. When I check my MySQL database there is no new pet created.

I know it is not "insert into owned adoptables' line because I double checked that a few times. So my only assumption is that is it is the cash. Though I can't seem to find the problem D:

Here is my doadopt page:
PHP:
<?php

// **********************************************************************
// Rusnak PHP Adoptables Script
// Copyright 2009 Brandon Rusnak
// For help and support: http://www.rusnakweb.com/forum/
//
// Redistribution prohibited without written permission
// **********************************************************************

// Wake the sleeping giant

// **********************************************************************
// Basic Configuration Info
// **********************************************************************

include("inc/functions.php");
include("inc/config.php");
include("lang/lang.php");

$themeurl = grabanysetting("themeurl");

// **********************************************************************
// Define our top links by calling getlinks()
// **********************************************************************

$links = getlinks();

// **********************************************************************
// Define our ads by calling getads()
// **********************************************************************

$ads = getads("any");

// **********************************************************************
// Grab any dynamic article content from the content table
// **********************************************************************

$pagecontent = getsitecontent("index");
$article_title = $pagecontent[title];
$article_content = $pagecontent[content];
$article_content = nl2br($article_content);

// **********************************************************************
// Grab any settings that we will need for the current page from the DB
// **********************************************************************

$browsertitle = grabanysetting("browsertitle");
$sitename = grabanysetting("sitename");
$slogan = grabanysetting("slogan");

// **********************************************************************
// Check and see if the user is logged in to the site
// **********************************************************************

$loginstatus = logincheck();
$isloggedin = $loginstatus[loginstatus];
$loggedinname = $loginstatus[username];

// **********************************************************************
// End Prepwork - Output the page to the user
// This file actually processes the adoption of a pet...
// **********************************************************************

$id = $_GET["id"];
$id = preg_replace("/[^a-zA-Z0-9s]/", "", $id);
$id = secure($id);

$promocode = $_GET["promocode"];
$promocode = preg_replace("/[^a-zA-Z0-9\\040.]/", "", $promocode);
$promocode = secure($promocode);

$name = $_GET["name"];
$name = preg_replace("/[^a-zA-Z0-9\\040.]/", "", $name);
$name = secure($name);

$genderratio = $_GET["genderratio"];
$genderratio = preg_replace("/[^a-zA-Z0-9\\040.]/", "", $genderratio);
$genderratio = secure($genderratio); 

$HP = $_GET["HP"];
$HP = preg_replace("/[^a-zA-Z0-9\\040.]/", "", $HP);
$HP = secure($HP); 

$MAXHP = $_GET["MAXHP"];
$MAXHP = preg_replace("/[^a-zA-Z0-9\\040.]/", "", $MAXHP);
$MAXHP = secure($MAXHP); 

$Attack = $_GET["Attack"];
$Attack = preg_replace("/[^a-zA-Z0-9\\040.]/", "", $Attack);
$Attack = secure($Attack); 

$Defense = $_GET["Defense"];
$Defense = preg_replace("/[^a-zA-Z0-9\\040.]/", "", $Defense);
$Defense = secure($Defense); 

$Speed = $_GET["Speed"];
$Speed = preg_replace("/[^a-zA-Z0-9\\040.]/", "", $Speed);
$Speed = secure($Speed); 

$Evade = $_GET["Evade"];
$Evade = preg_replace("/[^a-zA-Z0-9\\040.]/", "", $Evade);
$Evade = secure($Evade); 

$side = $_GET["side"];
$side = preg_replace("/[^a-zA-Z0-9\\040.]/", "", $side);
$side = secure($side); 

$Element = $_GET["Element"];
$Element = preg_replace("/[^a-zA-Z0-9\\040.]/", "", $Element);
$Element = secure($Element); 

if($isloggedin == "yes"){

// I guess the first thing to do is see if we have a valid adoptable ID submitted...

if($id == "" or !is_numeric($id)){

$article_title = $err_idnoexist;
$article_content = $err_idnoexist_text;

}
$query = "SELECT * FROM ".$prefix."owned_adoptables WHERE owner='".$loggedinname."' AND currentlevel<'5'";
$result = mysql_query($query);
$num = mysql_num_rows($result);

if($num >= 6){
$canadopt = "no";
$article_title = "Cannot Adopt!";
$article_content = "Sorry but you cannot adopt this Pokemon! You have six Pokemon under level 5 already, shoudn't you level them up first?";
}  
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."adoptables 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,"type");
$description=@mysql_result($result,$i,"description");
$eggimage=@mysql_result($result,$i,"eggimage");
$side=@mysql_result($result,$i,"side");
$genderratio=@mysql_result($result,$i,"genderratio"); 
$MAXHP=@mysql_result($result,$i,"MAXHP");
$Attack=@mysql_result($result,$i,"Attack");
$Defense=@mysql_result($result,$i,"Defense");
$Speed=@mysql_result($result,$i,"Speed");
$Evade=@mysql_result($result,$i,"Evade");
$Element=@mysql_result($result,$i,"Element");
$evolution=@mysql_result($result,$i,"evolution");
$evolutionlevel=@mysql_result($result,$i,"evolutionlevel");
$evolutionform=@mysql_result($result,$i,"evolutionform");  
$evolutionform2=@mysql_result($result,$i,"evolutionform2");  

$i++;
}

if($id == $aid){

// The ID submitted matches an existing adoptable type

$canadopt = canadopt($aid, "adopting", $promocode);

// If we can adopt this creature, do the adoption
// Otherwise we show an error...

if($canadopt == "yes"){

// **********************************************************************
// BEGIN the actual adoption process
// **********************************************************************

// First we see if we have a custom name.
// If not, we use the default name

if($name == ""){
$name = $type;
}

//The gender mod
if($genderratio >= 0 and $genderratio < 101) {
$tempgender = rand(0, 100);
if($tempgender >= 0 and $tempgender < $genderratio) {
$gender = "Female";
unset($tempgender);
}
else {
$gender = "Male";
unset($tempgender);
}
}
else {
$gender = "Genderless";
}


// Now we determine if we are using alternate images or not

$alts = getaltstatus($id, 0, 0);

// Now we determine if the user has enough cash left to purchase an adoptable, if its price status is enabled.

$pris = getpricestatus($id); 
$privp = getpricevaluep($id);
$privg = getpricevalueg($id);
$priva = getpricevaluea($id);
$privl = getpricevaluel($id);
$privo = getpricevalueo($id);
$privz = getpricevaluez($id);
$mypoke = getpoke($loggedinname);
$mygalu = getgalu($loggedinname);
$myakyi = getakyi($loggedinname);
$mylodo = getlodo($loggedinname);
$myoena = getoena($loggedinname);
$myzaqy = getzaqy($loggedinname);

$pokeleft = $mypoke - $privp;
$galuleft = $mygalu - $privg;
$akyileft = $myakyi - $priva;
$lodoleft = $mylodo - $privl;
$oenaleft = $myoena - $privo;
$zaqyleft = $myzaqy - $privz;

if($pokeleft < 0 or $galuleft < 0 or $akyileft < 0 or $lodoleft < 0 or $oenaleft < 0 or $zaqyleft < 0){
  $article_title = $name." cannot be adopted";
  $article_content = "It appears that you do not have enough money to acquire this adoptable, please come back later.";
}

else{

// Now we actually process the adoption and add it to the database...
// We need a unique code for the adoptable so we can show it to the user when we're done here...

$code = rand(1, 20000);


mysql_query("INSERT INTO ".$prefix."owned_adoptables VALUES ('', '$type', '$name','$loggedinname','0','0', '$code', '','$alts','fortrade','no','$gender','$loggedinname', 'Happy', '$side', '$MAXHP', '$MAXHP', '$Attack', '$Defense', '$Speed', '$Evade', '$Element','$evolution','$evolutionlevel','$evolutionform', '$evolutionform2'))");

//Next, the user's lost an amount of money equal to the adoptable's price value.
$query = "UPDATE ".$prefix."users SET poke='".$pokeleft."' WHERE username='".$loggedinname."'";
mysql_query($query);
$query = "UPDATE ".$prefix."users SET galu='".$galuleft."' WHERE username='".$loggedinname."'";
mysql_query($query);
$query = "UPDATE ".$prefix."users SET akyi='".$akyileft."' WHERE username='".$loggedinname."'";
mysql_query($query);
$query = "UPDATE ".$prefix."users SET lodo='".$lodoleft."' WHERE username='".$loggedinname."'";
mysql_query($query);
$query = "UPDATE ".$prefix."users SET oena='".$oenaleft."' WHERE username='".$loggedinname."'";
mysql_query($query);
$query = "UPDATE ".$prefix."users SET zaqy='".$zaqyleft."' WHERE username='".$loggedinname."'";
mysql_query($query);

// Adoption complete, show the user a confirmation screen...
// We need to show the adoptable info from the database...

$query = "SELECT * FROM ".$prefix."owned_adoptables WHERE code='$code' and owner='$loggedinname'";
$result = mysql_query($query);
$num = mysql_numrows($result);

//Loop out code
$i=0;
while ($i < 1) {
 
$id=@mysql_result($result,$i,"aid"); 


$i++;
}


$article_title = $name." adopted successfully";
$article_content = "<img src='".$eggimage."'><br>".$congrats1." ".$name.".  You can now manage ".$name." on the 
<a href='myadopts.php'>My Pokemon</a> page.<br><br><b><a href='myadopts.php?act=manage&id=".$aid."'>Click Here to Manage ".$name."</a><br>
<a href='myadopts.php?act=bbcode&id=".$aid."'>Click Here to get BBCodes / HTML Codes for ".$name."</a></b><br><br>
Be sure and <a href='levelup.php?id=".$aid."'>feed</a> ".$name." with clicks so that they grow!";
$query = "SELECT * FROM `adopts_users` WHERE `username`='$loggedinname'";
$result = mysql_query($query);
$num = mysql_numrows($result);
$TP = @mysql_result($result, $i, "points");
$gainTP = 30;
$addpoints = $TP + $gainTP;
mysql_query("UPDATE `adopts_users` SET `points`='" . $addpoints . "' WHERE `username`='$loggedinname'");

}

// **********************************************************************
// END the actual adoption process
// **********************************************************************


}
else{

$article_title = $accden;
$article_content = $adoptnoper;

}


} // End the if for if $id == $aid
else{

// Adoptable does not exist, show an error.

$article_title = $err_idnoexist;
$article_content = $err_idnoexist_text;

} // End the else for if $id == $aid


} // End the valid ID input else test statement (bulk of code goes above here)


} // End the log in check IF
else{

// Guests cannot adopt pets, so why bother...
$article_title = $guesttitleerror;
$article_content = $guesterror;

} // End the log in check ELSE 

// **********************************************************************
// Begin Template Definition
// **********************************************************************

//Define our current theme
$file = $themeurl;

// Do the template changes and echo the ready template
$template = file_get_contents($file);

$template = replace(':ARTICLETITLE:',$article_title,$template);
$template = replace(':ARTICLECONTENT:',$article_content,$template);
$template = replace(':ARTICLEDATE:',$article_date,$template);

$template = replace(':BROWSERTITLE:',$browsertitle,$template);
$template = replace(':SITENAME:',$sitename,$template);

//Define our links
$template = replace(':LINKSBAR:',$links,$template);

//Get the content for the side bar...

$sidebar = getsidebar();
$template = replace(':SIDEFEED:',$sidebar,$template);

//Get the ad content...
$template = replace(':ADS:',$ads,$template);

//Get the slogan info
$template = replace(':SLOGAN:',$slogan,$template);


echo $template;

// **********************************************************************
// End Template Definition
// **********************************************************************



?>
And my functions page:
PHP:
<?php

// File ID: functions.php
// Purpose: Provides basic sitewide functions

//Connect to the database first
connect();

//This function simply connects us to the database
function connect(){

    include("config.php");
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to MySQL');
    mysql_select_db($dbname);

}

//This function performs security checks on all incoming form data
function secure($data){

if(is_array($data)){
die("Hacking Attempt!");
}


//MySQL Real Escape String
$data = mysql_real_escape_string($data);

//Strip HTML tags
$data = strip_tags($data, '');

return $data;

}

function getsitecontent($page){

include("config.php");


$query = "SELECT * FROM ".$prefix."content WHERE page = '$page'";
$result = @mysql_query($query);
$num = @mysql_numrows($result);


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

$title=@mysql_result($result,$i,"title");
$content=@mysql_result($result,$i,"content");

$title = stripslashes($title);
$content = stripslashes($content);

$i++;
}

$value[content] = $content;
$value[title] = $title;

return $value;
}

//This function replaces template values
function replace($old,$new,$template)
    {
    $template = str_replace($old, $new, $template);
    return $template;
    }

function logincheck(){

include("config.php");

//Function to determine if user is logged in.

//Set up our login info...
$username = "";
$password = "";

//Check for cookie

if (isset($_COOKIE['auser']) and isset($_COOKIE['apass'])){

$username = $_COOKIE['auser'];
$password = $_COOKIE['apass'];

$username = preg_replace("/[^a-zA-Z0-9\\040.]/", "", $username);
$username = secure($username);
$password = secure($password);

//Run login operation
$query = "SELECT * FROM ".$prefix."users WHERE username = '$username'";
$result = mysql_query($query);
$num = mysql_numrows($result);

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

$luser=@mysql_result($result,$i,"username");
$lpass=@mysql_result($result,$i,"password");

$i++;
}

    if($username == $luser and $password == $lpass){
        $isloggedin = "yes";
    }
    else{
    if (isset($_COOKIE['auser'])){
    $past = time() - 10; 
    setcookie("auser",$username,$past);
    }

    if (isset($_COOKIE['apass'])){
    $past = time() - 10; 
    setcookie("apass",$password,$past);
    }
    $isloggedin = "no";
    }

}
else
{
//User is not logged in
$isloggedin = "no";

} 

//Return our user data
$userdata[loginstatus] = $isloggedin;
$userdata[username] = $username;

return $userdata;

}

function getpoke($loggedinname){

include("config.php");

//First we see if we are logged in or not

$loginstatus = logincheck();
$isloggedin = $loginstatus[loginstatus];
$loggedinname = $loginstatus[username];

$query = "SELECT * FROM ".$prefix."users WHERE username = '$loggedinname'";
$result = @mysql_query($query);
$num = @mysql_numrows($result);

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

$poke=@mysql_result($result,$i,"poke");

$i++;
}

return $poke;

}
function getgalu($loggedinname){

include("config.php");

//First we see if we are logged in or not

$loginstatus = logincheck();
$isloggedin = $loginstatus[loginstatus];
$loggedinname = $loginstatus[username];

$query = "SELECT * FROM ".$prefix."users WHERE username = '$loggedinname'";
$result = @mysql_query($query);
$num = @mysql_numrows($result);

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

$galu=@mysql_result($result,$i,"galu");

$i++;
}

return $galu;

}
function getakyi($loggedinname){

include("config.php");

//First we see if we are logged in or not

$loginstatus = logincheck();
$isloggedin = $loginstatus[loginstatus];
$loggedinname = $loginstatus[username];

$query = "SELECT * FROM ".$prefix."users WHERE username = '$loggedinname'";
$result = @mysql_query($query);
$num = @mysql_numrows($result);

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

$akyi=@mysql_result($result,$i,"akyi");

$i++;
}

return $akyi;

}
function getlodo($loggedinname){

include("config.php");

//First we see if we are logged in or not

$loginstatus = logincheck();
$isloggedin = $loginstatus[loginstatus];
$loggedinname = $loginstatus[username];

$query = "SELECT * FROM ".$prefix."users WHERE username = '$loggedinname'";
$result = @mysql_query($query);
$num = @mysql_numrows($result);

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

$lodo=@mysql_result($result,$i,"lodo");

$i++;
}

return $lodo;

}
function getoena($loggedinname){

include("config.php");

//First we see if we are logged in or not

$loginstatus = logincheck();
$isloggedin = $loginstatus[loginstatus];
$loggedinname = $loginstatus[username];

$query = "SELECT * FROM ".$prefix."users WHERE username = '$loggedinname'";
$result = @mysql_query($query);
$num = @mysql_numrows($result);

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

$oena=@mysql_result($result,$i,"oena");

$i++;
}

return $oena;

}
function getzaqy($loggedinname){

include("config.php");

//First we see if we are logged in or not

$loginstatus = logincheck();
$isloggedin = $loginstatus[loginstatus];
$loggedinname = $loginstatus[username];

$query = "SELECT * FROM ".$prefix."users WHERE username = '$loggedinname'";
$result = @mysql_query($query);
$num = @mysql_numrows($result);

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

$zaqy=@mysql_result($result,$i,"zaqy");

$i++;
}

return $zaqy;

}


function grabanysetting($where){

include("config.php");

$query = "SELECT * FROM ".$prefix."settings WHERE name = '".$where."'";
$result = @mysql_query($query);
$num = @mysql_numrows($result);

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

$value=@mysql_result($result,$i,"value");
$value = stripslashes($value);
$i++;
}
return $value;
}

function getlinks(){

include("config.php");

//This function gets the links for the top bar from the database 

/*

$links = "<li><a href='index.php'>Home</a></li>
<li><a href='adopt.php'>Adopt</a></li>
<li><a href='myadopts.php'>My Adopts</a></li>
<li><a href='account.php'>My Account</a></li>
<li><a href='messages.php'>Message Center</a></li>
<li><a href='trade.php'>Trade Adopts</a></li>
<li><a href='featured.php'>Popular</a></li>";

*/

// We will be getting our links from the database...

$links = "";

    $query = "SELECT * FROM ".$prefix."links ORDER BY id ASC";
    $result = mysql_query($query);
    $num = mysql_numrows($result);

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

    $linktext=@mysql_result($result,$i,"linktext");
    $linkurl=@mysql_result($result,$i,"linkurl");

    $linktext = stripslashes($linktext);

    $links = $links."<li><a href='".$linkurl."'>".$linktext."</a></li>";

    $i++;
    }


return $links;

}

function getsidebar(){

include("config.php");

//This function determines what shows in the side bar of the template
//This will most likely be either a login prompt, quick account access, or something else

//First we see if we are logged in or not

$loginstatus = logincheck();
$isloggedin = $loginstatus[loginstatus];
$loggedinname = $loginstatus[username];

if($isloggedin == "yes"){

$msgctr = "<a href='messages.php'>Visit Message Center</a><br>";

$query = "SELECT * FROM ".$prefix."messages WHERE touser='".$loggedinname."' and status='unread'";
$result = mysql_query($query);
$num = mysql_numrows($result);

if($num > 0){
$msgctr = "<a href='messages.php'>Visit Message Center <b>(".$num.")</b></a><br>";
}

$sidebar = "<center><b><u>".$loggedinname."'s PokeDex:</u></b><br><br>
<a href='myadopts.php'>Manage Party</a><br>
<a href='mycash.php'>Check Cash</a><br>
<a href='account.php'>Access Computer</a><br>
<a href='profile.php?user=".$loggedinname."'>My Profile</a><br>
".$msgctr."
<a href='logout.php'>Log Out</a></center>";

}
else{

$sidebar = "<b><u>Member Login:</u></b><br><br>
<form name='form1' method='post' action='login.php'>
  Username: 
    <input name='username' type='text' id='username'>

  Password: 
    <input name='password' type='password' id='password'>
  
    <input type='submit' name='Submit' value='Log In'>
</form><a href='register.php'>Don't have an account? Register!</a><br><a href='forgotpass.php'>Forgot Password?</a>";

}




return $sidebar;

}

function dologin($username, $password){

//This function logs a user in...

include("config.php");

$query = "SELECT * FROM ".$prefix."users WHERE username = '$username'";
$result = @mysql_query($query);
$num = @mysql_numrows($result);

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

$luser=@mysql_result($result,$i,"username");
$lpass=@mysql_result($result,$i,"password");

$i++;
}

if($username == $luser and $password == $lpass){
$status = "success";

//If the cookie already exists for some reason, delete it

if (isset($_COOKIE['auser']) and isset($_COOKIE['apass'])){

$past = time() - 10; 
setcookie("auser",$username,$past);
setcookie("apass",$password,$past);

}



// Set the cookie
$Month = 2592000 + time();
setcookie("auser",$username,$Month);
setcookie("apass",$password,$Month);

}
else{
$status = "error";
}



return $status;

}

function getgroup(){

//This function gets the numerical usergroup ID of a user, or returns 0 if is a guest

include("config.php");

$loginstatus = logincheck();
$isloggedin = $loginstatus[loginstatus];
$loggedinname = $loginstatus[username];

if($isloggedin == "yes"){

$query = "SELECT * FROM ".$prefix."users WHERE username = '$loggedinname'";
$result = @mysql_query($query);
$num = @mysql_numrows($result);

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

$group=@mysql_result($result,$i,"usergroup");

$i++;
}

return $group;

}
else{
return 0;
}

}

function cancp($usergroup){

include("config.php");

//This function determines if a usergroup is allowed to access the Admin CP

$query = "SELECT * FROM ".$prefix."groups WHERE gid = '$usergroup'";
$result = @mysql_query($query);
$num = @mysql_numrows($result);

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

$cancp=@mysql_result($result,$i,"cancp");

$i++;
}

if($cancp == "" or $usergroup == 0){
$cancp = "no";
}

return $cancp;

}

function getadmlinks(){

include("config.php");

//This function shows special links to the site admin

$links = "<li><a href='index.php'>Home</a></li>
<li><a href='admin.php?set=adopts'>Change Adoptables</a></li>
<li><a href='admin.php?set=content'>Change Content</a></li>
<li><a href='admin.php?set=users'>Change Users</a></li>
<li><a href='admin.php?set=settings'>Site Settings</a></li>
<li><a href='admin.php?set=ads'>Manage Ads</a></li>";



return $links;

}

function cando($usergroup, $do){

include("config.php");

//This function determines if a usergroup is allowed to do a specific task

$query = "SELECT * FROM ".$prefix."groups WHERE gid = '$usergroup'";
$result = @mysql_query($query);
$num = @mysql_numrows($result);

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

$cando=@mysql_result($result,$i,$do);

$i++;
}

if($cando == "" or $usergroup == 0){
$cando = "no";
}

return $cando;

}

function canadopt($aid, $cond, $promocode){

include("config.php");

// This function determines if a user can adopt a specific adoptable...

$canadopt = "yes"; // The default status is that we CAN adopt, unless proven false...

// The first thing we check is that we are logged in

$loginstatus = logincheck();
$isloggedin = $loginstatus[loginstatus];
$loggedinname = $loginstatus[username];

if($isloggedin != "yes" and $cond != "showing"){
$canadopt = "no";
}

// Now we check if our usergroup has permission to adopt the adoptable...

$group = getgroup();
$dbcanadpt = cando($group, "canadopt");

if($dbcanadpt != "yes" and $cond != "showing"){
$canadopt = "no";
}

// We need to pull a lot of junk from the database for these next few checks


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

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

$whenisavail=@mysql_result($result,$i,"whenisavail"); 
$correctpromocode=@mysql_result($result,$i,"promocode"); 
$freqcond=@mysql_result($result,$i,"freqcond"); 
$number=@mysql_result($result,$i,"number"); 
$date=@mysql_result($result,$i,"date"); 
$datecond=@mysql_result($result,$i,"datecond");
$adoptscond=@mysql_result($result,$i,"adoptscond"); 




$morethannumberen=@mysql_result($result,$i,"moreless"); 
$morethannumber=@mysql_result($result,$i,"morelessnum"); 
$usergroupsen=@mysql_result($result,$i,"levelgrle"); 
$usergroupid=@mysql_result($result,$i,"grlelevel"); 

$type=@mysql_result($result,$i,"type");

$i++;
}

// Now we check if the adoptable requires a promo code and if the promo code submitted is correct...

if($whenisavail == "promo" and $promocode != $correctpromocode){

// A promo code is required but the submitted promo code is not the correct code
$canadopt = "no";

}

// Now we check those three conditions we have in the Admin CP
// If ANY of them fails, this check fails!

if($whenisavail == "conditions"){

    // If we have a restriction on the number of times this can be adopted...

    if($freqcond == "enabled"){

    // We have a frequency based condition
    // Select from the database and determine how many times this adoptable type has been adopted

    $num = 0;

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

        if($num > $number){
        
        // Not Available
        $canadopt = "no";
    
        }


    } // End the frequency condition IF statement

    // Begin the date restriction check

    $today = date('Y-m-d');

    if($datecond == "enabled" and $date != $today){
    
    $canadopt = "no";
    
    }

    // We are checking to see how many of this adoptable a user owns
    // If they own more than the specifed number, they cannot adopt...

    

    if($morethannumberen == "enabled"){

    $num = 0;

    $query = "SELECT * FROM ".$prefix."owned_adoptables WHERE owner='$loggedinname' and type='$type'";
    $result = mysql_query($query);
    $num = mysql_numrows($result);

    if($num > $morethannumber){

    $canadopt = "no";


    }


    } // End morethannumberen check

    
    

    // Check if the user is of a specified usergroup...

    if($usergroupsen == "enabled"){

    $ourgid = getgroup();

    // If the two numbers do not match, do not allow the adoption...

        if($ourgid != $usergroupid){

        $canadopt = "no";

        }    


    }
    
    
    

} // End the is there conditions if statement


return $canadopt;

}

function getaltstatus($parentid, $childid, $childlevel){

include("config.php");

// This function determines if we will use alternate images...
// All this does is give us a yes or no
// This does NOT actually assign the alternate images in the DB.....

$altstatus = "no";
$run = "no";

// First we need to see if this adoptable type has alternate images enabled...

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

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

$alternates=@mysql_result($result,$i,"alternates"); 
$altoutlevel=@mysql_result($result,$i,"altoutlevel");
$altchance=@mysql_result($result,$i,"altchance");

$i++;
}

// If alternate images are enabled, we must run some checks to see if we use them...

if($alternates == "enabled"){


// Let's see if the level we are on is the level that requires alternates
// If we're not on a level that requires to check alternates, why bother?

    if($childlevel == $altoutlevel){
    
    
    $run = "yes";
    
    }



}
}

function getpricestatus($aid){

include("config.php");

// This function determines if we will charge a price on users adopting a given pet...
// All this does is give us a yes or no...

$pricestatus = "no";

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

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

$pricestatus=@mysql_result($result,$i,"pricestatus");

$i++;
}

return $pricestatus;

}

function getpricevaluep($aid){

include("config.php");

//This function retrieves an adoptable's price from sql database.

$pricestatus = "no";

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

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

$pricestatus=@mysql_result($result,$i,"pricestatus");
$pricevaluep=@mysql_result($result,$i,"pricevaluep");
$i++;
}

if($pricestatus == "enabled"){
$pricevalp = $pricevaluep;
}
else{
$pricevalp = 0;
}

return $pricevalp;

}
function getpricevalueg($aid){

include("config.php");

//This function retrieves an adoptable's price from sql database.

$pricestatus = "no";

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

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

$pricestatus=@mysql_result($result,$i,"pricestatus");
$pricevalueg=@mysql_result($result,$i,"pricevalueg");
$i++;
}

if($pricestatus == "enabled"){
$pricevalg = $pricevalueg;
}
else{
$pricevalg = 0;
}

return $pricevalg;

}
function getpricevaluea($aid){

include("config.php");

//This function retrieves an adoptable's price from sql database.

$pricestatus = "no";

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

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

$pricestatus=@mysql_result($result,$i,"pricestatus");
$pricevaluea=@mysql_result($result,$i,"pricevaluea");
$i++;
}

if($pricestatus == "enabled"){
$pricevala = $pricevaluea;
}
else{
$pricevala = 0;
}

return $pricevala;

}
function getpricevaluel($aid){

include("config.php");

//This function retrieves an adoptable's price from sql database.

$pricestatus = "no";

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

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

$pricestatus=@mysql_result($result,$i,"pricestatus");
$pricevaluel=@mysql_result($result,$i,"pricevaluel");
$i++;
}

if($pricestatus == "enabled"){
$pricevall = $pricevaluel;
}
else{
$pricevall = 0;
}

return $pricevall;

}
function getpricevalueo($aid){

include("config.php");

//This function retrieves an adoptable's price from sql database.

$pricestatus = "no";

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

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

$pricestatus=@mysql_result($result,$i,"pricestatus");
$pricevalueo=@mysql_result($result,$i,"pricevalueo");
$i++;
}

if($pricestatus == "enabled"){
$pricevalo = $pricevalueo;
}
else{
$pricevalo = 0;
}

return $pricevalo;

}
function getpricevaluez($aid){

include("config.php");

//This function retrieves an adoptable's price from sql database.

$pricestatus = "no";

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

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

$pricestatus=@mysql_result($result,$i,"pricestatus");
$pricevaluez=@mysql_result($result,$i,"pricevaluez");
$i++;
}

if($pricestatus == "enabled"){
$pricevalz = $pricevaluez;
}
else{
$pricevalz = 0;
}

return $pricevalz;

}

function getcurrentimage($id){

// This function determines which image we should use for a given adoptable...

include("config.php"); // This is so we can use the table prefix

$image = "";

// First we select the adoptable from the database and get some basic information...

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

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

$type=@mysql_result($result,$i,"type"); 
$currentlevel=@mysql_result($result,$i,"currentlevel"); 
$imageurl=@mysql_result($result,$i,"imageurl");
$usealternates=@mysql_result($result,$i,"usealternates");


$i++;
}

if($imageurl != ""){

// If we are using a custom image for this adoptable, use that
$image = $imageurl;

}
else{

// We have to dig this up ourselves...
// Check if we are using an egg image or a level image...

    if($currentlevel == 0 or $currentlevel == "0"){

    // Let's see what the egg image is...    

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

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

    $eggimage=@mysql_result($result,$i,"eggimage"); 


    $i++;
    }

    $image = $eggimage; // Set the image URL equal to the egg image...

    }
    else{

    // We have to find out what level we are using...
    // Then we can choose the appropriate image for what we are using...

        $query = "SELECT * FROM ".$prefix."levels WHERE adoptiename='$type' and thisislevel='$currentlevel'";
        $result = mysql_query($query);
        $num = mysql_numrows($result);

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

        $primaryimage=@mysql_result($result,$i,"primaryimage"); 
        $alternateimage=@mysql_result($result,$i,"alternateimage");


        $i++;
        }

        // If alternate images are enabled and an alternate image exists, use it

        if($usealternates == "yes" and $alternateimage != ""){

        $image = $alternateimage; // Use the alternate image

        }
        else{

        $image = $primaryimage; // Set the image equal to the primary image for the level

        }
    


    }

}

if($type == "" or $image == ""){

// We did not settle on an image, so we show an error image...

$image = "http://www.".$domain."".$scriptpath."/templates/icons/delete.gif";

}


return $image;

}

function getcurrentlevel($id){

// This function gets the current level of an adoptable...

include("config.php");

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

//Loop out code
$i=0;
while ($i < 1) {
 
$currentlevel=@mysql_result($result,$i,"currentlevel"); 


$i++;
}

if($currentlevel == ""){

$currentlevel = "error"; // If the adoptable does not have a current level or does not exist, we return an error...

}

// Return the level

return $currentlevel;


}

function getnextlevelexists($type, $currentlevel){

include("config.php");

// This function determines if a higher level exists for an adopt, or if it is at max level.

$query = "SELECT * FROM ".$prefix."levels WHERE adoptiename='$type' and thisislevel > '$currentlevel'";
$result = mysql_query($query);
$num = mysql_numrows($result);

$exists = "false";

if($num > 0){

$exists = "true"; // A higher level exists

}

return $exists;

}
function getcurrenteggstage($id){

// This function gets the current egg stage of an adoptable...

include("config.php");

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

//Loop out code
$i=0;
while ($i < 1) {
 
$currenteggstage=@mysql_result($result,$i,"eggstage"); 


$i++;
}

if($currenteggstage == ""){

$currenteggstage = "error"; // If the adoptable does not have a current egg stage or does not exist, we return an error...

}

// Return the level

return $currenteggstage;


}

function getnexteggstageexists($type, $currenteggstage){

include("config.php");

// This function determines if a higher level exists for an adopt, or if it is at max eggstage and ready to hatch.

$query = "SELECT * FROM ".$prefix."eggstages WHERE adoptiename='$type' and eggstage > '$currenteggstage'";
$result = mysql_query($query);
$num = mysql_numrows($result);

$exists = "false";

if($num > 0){

$exists = "true"; // A higher egg stage exists, the adoptable is not ready to hatch

}

return $exists;

}

function convertidtotype($id){

// This function takes in an adoptable's ID and returns the type of adoptable it is...

include("config.php"); 

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

//Loop out code
$i=0;
while ($i < 1) {
 
$type=@mysql_result($result,$i,"type"); 


$i++;
}

if($type == ""){

$type = "error";

}

return $type;

}

function converttypetoparentid($type){

// This function takes in an adoptable type and returns the ID of the parent

include("config.php");

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

//Loop out code
$i=0;
while ($i < 1) {
 
$id=@mysql_result($result,$i,"id"); 


$i++;
}

if($id == ""){
$id = "error";
}

return $id;

}

function reward($id, $type, $currentlevel, $owner){

include("config.php");

// This function determines if we are giving the user a reward or not...

$query = "SELECT * FROM ".$prefix."levels WHERE adoptiename='$type' and thisislevel='$currentlevel'";
$result = mysql_query($query);
$num = mysql_numrows($result);

//Loop out code
$i=0;
while ($i < 1) {
 
$rewarduser=@mysql_result($result,$i,"rewarduser"); 
$promocode=@mysql_result($result,$i,"promocode");


$i++;
}

if($rewarduser == "yes" and $promocode != ""){

// We are sending out a reward...

$mtitle = "You have received a reward!";
$mtext = "Congratulations!  You have received a reward because one of your adoptables leveled up and the site admin has chosen to reward you for this.<br><br>
<b><u>Your reward is the following promo code:</u></b> ".$promocode."<br><br>
You may use this promo code on the <a href='promo.php?promocode=".$promocode."'>Promo Code Page</a> to receive a special exclusive or limited edition adoptable!<br><br>
Congratulations on your reward!";

$mtext = mysql_real_escape_string($mtext);

$date = date('Y-m-d');
$query = "INSERT INTO ".$prefix."messages VALUES ('', 'SYSTEM', '$owner','unread','$date','$mtitle', '$mtext')";
mysql_query($query);

// Now we check if we are sending out an email to the user alerting them of the message...

$query = "SELECT * FROM ".$prefix."users WHERE username='".$owner."'";
$result = mysql_query($query);
$num = mysql_numrows($result);

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

$newmessagenotify=@mysql_result($result,$i,"newmessagenotify");
$email=@mysql_result($result,$i,"email"); 

$i++;
}

if($newmessagenotify == 1){

// We are sending this user an email about the new message...

    $systememail = grabanysetting("systememail");
    
    $headers = "From: ".$systememail."";

    $site_name = grabanysetting("sitename");

    $message = "Hello ".$owner.";\n\nYou have received a new Private Message from SYSTEM at ".$site_name." with the title ".$mtitle.".\n
    You can read this message at: http://www.".$domain."".$scriptpath."/messages.php\n
    Thank You.  The ".$site_name." team.";

    mail($email, $site_name." - You Have Received a Reward", $message, $headers);

}



}

return $rewardstatus;

}

function getadmimages(){

include("config.php");

$formcontent = "";

$query = "SELECT * FROM ".$prefix."filesmap";
$result = mysql_query($query);
$num = mysql_numrows($result);

//Loop out code
$i=0;
while ($i < $num) {
 
$wwwpath=@mysql_result($result,$i,"wwwpath");
$friendlyname=@mysql_result($result,$i,"friendlyname");

$formcontent = $formcontent."<option value='".$wwwpath."'>".$friendlyname."</option>";


$i++;
}

return $formcontent;

}

function deleteuser($user){

include("config.php");

//This function deletes a user from the system...

$user = secure($user);

$query = "DELETE FROM ".$prefix."users WHERE username = '".$user."'";
$result = mysql_query($query);

$query = "DELETE FROM ".$prefix."owned_adoptables WHERE owner = '".$user."'";
$result = mysql_query($query);

}

function getads($page){

// Function to display site advertisements

include("config.php");

if($page == "any"){
$page = "";
}

$query = "SELECT * FROM ".$prefix."ads WHERE page = '".$page."' and status = 'active' ORDER BY RAND() LIMIT 1";
$result = @mysql_query($query);
$num = @mysql_numrows($result);

if($num > 0){

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

$value=@mysql_result($result,$i,"text");
$value = stripslashes($value);
$aid=@mysql_result($result,$i,"id");
$actualimpressions=@mysql_result($result,$i,"actualimpressions");
$impressions=@mysql_result($result,$i,"impressions");
$i++;
}

if($impressions == ""){
$impressions = 0;
}

$actualimpressions = $actualimpressions + 1;

//Update the impressions count
$query = "UPDATE ".$prefix."ads SET actualimpressions='".$actualimpressions."' WHERE id='".$aid."'";
mysql_query($query);

//Check that ad is not over max impressions...
if ($actualimpressions >= $impressions and $impressions != 0){
$query = "UPDATE ".$prefix."ads SET status='inactive' WHERE id='".$aid."'";
mysql_query($query);
}


}
else{
$value = "";
}

return $value;

}


function getabandonedimage($id){

// This function determines which image we should use for a given adoptable...

include("config.php"); // This is so we can use the table prefix

$image = "";

// First we select the adoptable from the database and get some basic information...

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

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

$type=@mysql_result($result,$i,"type"); 
$currentlevel=@mysql_result($result,$i,"currentlevel"); 
$imageurl=@mysql_result($result,$i,"imageurl");
$usealternates=@mysql_result($result,$i,"usealternates");


$i++;
}

if($imageurl != ""){

// If we are using a custom image for this adoptable, use that
$image = $imageurl;

}
else{

// We have to dig this up ourselves...
// Check if we are using an egg image or a level image...

    if($currentlevel == 0 or $currentlevel == "0"){

    // Let's see what the egg image is...    

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

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

    $eggimage=@mysql_result($result,$i,"eggimage"); 


    $i++;
    }

    $image = $eggimage; // Set the image URL equal to the egg image...

    }
    else{

    // We have to find out what level we are using...
    // Then we can choose the appropriate image for what we are using...

        $query = "SELECT * FROM ".$prefix."levels WHERE adoptiename='$type' and thisislevel='$currentlevel'";
        $result = mysql_query($query);
        $num = mysql_numrows($result);

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

        $primaryimage=@mysql_result($result,$i,"primaryimage"); 
        $alternateimage=@mysql_result($result,$i,"alternateimage");


        $i++;
        }

        // If alternate images are enabled and an alternate image exists, use it

        if($usealternates == "yes" and $alternateimage != ""){

        $image = $alternateimage; // Use the alternate image

        }
        else{

        $image = $primaryimage; // Set the image equal to the primary image for the level

        }
    


    }

}

if($type == "" or $image == ""){
// We did not settle on an image, so we show an error image...

$image = "http://".$domain."".$scriptpath."/templates/icons/delete.gif";

}

return $image;

}

function canadoptab($aid, $cond, $promocode){

include("config.php");

// This function determines if a user can adopt a specific adoptable...

$canadopt = "yes"; // The default status is that we CAN adopt, unless proven false...

// The first thing we check is that we are logged in

$loginstatus = logincheck();
$isloggedin = $loginstatus[loginstatus];
$loggedinname = $loginstatus[username];

if($isloggedin != "yes" and $cond != "showing"){
$canadopt = "no";
}

// Now we check if our usergroup has permission to adopt the adoptable...

$group = getgroup();
$dbcanadpt = cando($group, "canadopt");

if($dbcanadpt != "yes" and $cond != "showing"){
$canadopt = "no";
}
return $canadopt;

} 

?>

Can anyone see what I'm overlooking? I'm still trying to solve the issue on my own but I thought posting it and getting other help might be good too :3
 
Invalid adoptable id error is usually caused by mismatch of your owned_adoptables table and this line in doadopt.php below:

PHP:
mysql_query("INSERT INTO ".$prefix."owned_adoptables VALUES ('', '$type', '$name','$loggedinname','0','0', '$code', '','$alts','fortrade','no','$gender','$loggedinname', 'Happy', '$side', '$MAXHP', '$MAXHP', '$Attack', '$Defense', '$Speed', '$Evade', '$Element','$evolution','$evolutionlevel','$evolutionform', '$evolutionform2'))");

I'd advise you to look at your prefix_owned_adoptables table carefully, or you may want to post a screenshot of your database table structure of prefix_owned_adoptables.

Also I recommend you to edit out this part of the codes from all your script files:

PHP:
// **********************************************************************
// Rusnak PHP Adoptables Script
// Copyright 2009 Brandon Rusnak
// For help and support: http://www.rusnakweb.com/forum/
//
// Redistribution prohibited without written permission
// **********************************************************************
 
Invalid adoptable id error is usually caused by mismatch of your owned_adoptables table and this line in doadopt.php below:

PHP:
mysql_query("INSERT INTO ".$prefix."owned_adoptables VALUES ('', '$type', '$name','$loggedinname','0','0', '$code', '','$alts','fortrade','no','$gender','$loggedinname', 'Happy', '$side', '$MAXHP', '$MAXHP', '$Attack', '$Defense', '$Speed', '$Evade', '$Element','$evolution','$evolutionlevel','$evolutionform', '$evolutionform2'))");
I'd advise you to look at your prefix_owned_adoptables table carefully, or you may want to post a screenshot of your database table structure of prefix_owned_adoptables.

Also I recommend you to edit out this part of the codes from all your script files:

PHP:
// **********************************************************************
// Rusnak PHP Adoptables Script
// Copyright 2009 Brandon Rusnak
// For help and support: http://www.rusnakweb.com/forum/
//
// Redistribution prohibited without written permission
// **********************************************************************
Yeah I first thought that would be the problem but after checking it over and over again I realized it was not :S I did just re-check it again and it's exactly like my owned_adoptables table. That's why I'm thinking it's the cash since I can see no other issues and I could adopt pets before I installed the purchasing mod.

Alrighty :3
 
Fix the insert query! Try to use this one
PHP:
mysql_query("INSERT INTO ".$prefix."owned_adoptables VALUES ('', '$type', '$name','$loggedinname','0','0', '$code', '','$alts','fortrade','no','$gender','$loggedinname', 'Happy', '$side', '$MAXHP', '$MAXHP', '$Attack', '$Defense', '$Speed', '$Evade', '$Element','$evolution','$evolutionlevel','$evolutionform', '$evolutionform2')");
 
Oh! *facepalm* I always make tiny mistakes like that XD Lol an extra )

Thank you! :D

(though I probably should test out adoptables with cash before I call this topic done XD)
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,280
Messages
33,130
Members
1,603
Latest member
Monako
BETA

Latest Threads

Top