Breeding

Forum
Last Post
Threads / Messages

Arianna

Dev Staff
Staff member
Dev Staff
Joined
Sep 25, 2009
Messages
334
Points
0
Age
27
Mysidian Dollar
13,840
Yes, I know that this will take a lot of work and I'm certainly not the right person to be doing this, given my knowledge of PHP.
Is anyone here making a script right now, or would anyonee like to give me some help on my current page (which is very drafty and probably not the right way to code it)?

Here's my current code, if anyone would like to look and help me. Most of the things which I need help on are in comments, where I have no idea what to do.

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");

$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
// **********************************************************************


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

$query = "SELECT * FROM ".$prefix."owned_adoptables WHERE level='2' AND owner='$loggedinname'"; //is this how we select it, somehow?

if($isloggedin == "yes"){
/////How do I define what the parents are equal to? Like $parent1 == aid76 or something like that. How do I choose?

//how do I select which adoptable I'm looking at here. basically what I'm trying to do is say:
//If *this* adoptable's gender is female, follow this script. But right now, I'm only saying if the variable $gender is female. xP
if ($gender == female && $aid == ??? ) { //can I use getelementbyid or something like that?
///do I use this:
//$query = "SELECT * FROM ".$prefix."owned_adoptables WHERE gender=male";
//or this, which is under this line?
if ($owner == $loggedinname && $gender == "male") {
//here we display all the males the adoptable can breed with
//how do I list them?
//basically I'd list them here
//loop out the code with i++ or the like, right?
//and all of them would be sort of like, if you click on them, it sets them as the parent2 variable, right?
}

/* //// Now we're going to start making the adoptable
   //// We have to define three things:
   //// It's gender, it's type, and if it's an alt (I don't know how to define alts, please help!)
*/
// **********************************************************************
// ADOPTABLE GENDER
// **********************************************************************
// I'm pretty confident on this. I think I understand it. I like it being random.
$tempgender = rand(0, 1);
if($tempgender == "0") {
$gender = "female";
unset($tempgender);
}
else {
$gender = "male";
unset($tempgender);
}

// **********************************************************************
// ADOPTABLE TYPE
// **********************************************************************
// This comes from one of the two parents. I don't get how to make this part.
// What I want is if $temptype turns out to be '0', we set $type to the $type of parent 1
// Otherwise it sets to be the type of parent 2
$temptype = rand(0,1);
if($temptype == "0") {
$type = ???? //This needs to be the type of parent #1
//Do I use? $query = "SELECT * FROM ".$prefix."owned_adoptables WHERE aid=[parent1's aid]"; and then somehow get the type?
unset($temptype); }

else {
$type = ???? //This needs to be the type of parent #2
//see above, where the same question was stated for parent1.
unset($temptype); }

}

// so we've declared everything, time to produce the adoptable
// **********************************************************************
// ADOPTABLE IS BORN!
// **********************************************************************
mysql_query("INSERT INTO".$prefix."owned_adoptables VALUES ('','$type','$loggedinname','0','0','$code','$alts','notfortrade','no','$gender')");

// We have now made the adoptable, take us to the myadopts page.
// TAKE US TO MYADOPTS.PHP
$article_title = $name." was born!";
$article_content = "<img src='".$eggimage."'><a href='myadopts.php'>Manage ".$name." now!</a>"

}
// *****************************************************************************
// Yay, we're done! Well, sort of. Can you help me with what I don't understand?
// *****************************************************************************
else {
$article_content = $article_content."<p><b> Guests can't breed. Please register or login. </b></p>";
}


// **********************************************************************
// 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
// **********************************************************************



?>

Thanks,
Arianna
 
What I would recommend is that you use the alternate images system as a basis for gendering your adoptables. Make each adoptable have a 1 in 2 chance of using the alternate images. Then when you make new adoptables always use alternate images and make the primary images female and the alternates male. That way then you have a 50/50 shot of getting a male or female adoptable.

Then for breeding, simply check if the adoptable is using the primary or alternate images. So, for sample breeding what you could do is check if the user has one adoptable of type x that is male and one of type x that is female. If they do, then they are allowed to breed. :)

Hope it helps,
Brandon
 
Hmm, that makes sense. However, I already made the whole gender system and I quite like it. :/ We have alt images which are different things (not female/male) so I don't think that that would work.
Is there any way that this script would ever work, or would it make sense to scrap it?
 
I would do like that: create a table to store adoptables that users want do breed

then create a page so users can put the adoptables there, like a 'daycare', and while they are there, they are removed from the owned_adoptables

then a page that displays the adoptables in the daycare, and allows users to choose if there's any that they want to breed with, and when they choose, the other adoptable go to the daycare table too, and also the date is inserted, so you can put something that allows the user to return and see if they bred well just after some days

and I guess each user has to keep one egg.. idk

just some ideas '-'
 
I was thinking more of an instant system. I don't really know what to do. Do you think that your way would make it harder or easier for a PHP novice like me to complete?
Does anyone have any advice on the pieces of code I'm missing?
 
that way would be harder I guess '-' but I don't understand very well what you're trying to do x_x
is it like, just breeding two of your adoptables into one new?

I'm a PHP novice too like you, but I'll see your code e_e

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

$query = "SELECT * FROM ".$prefix."owned_adoptables WHERE level='2' AND owner='$loggedinname'"; //is this how we select it, somehow?

for this part... you have to estabilish a $result variable first, and the $query is not being used at all.. also, the 'level' is not a colum in owned_adoptables.. do you want to select the rows just from the adoptables that are level 2?

well I'll guess you forgot an important thing.. how the user will select the adoptables that he wants to breed? .-.
I'll try to create a code to that and I'll post here
but I'm not sure I can haha x_x
 
Basically what I want is that the user selects adoptable 'a' which is a female, and then it displays all males. They then choose the male. This sets adoptable a's id to parent1 and adoptable b's id to parent2. This then determines how the egg with be.
I'm a PHP beginner would be better to describe it. The only thing I've learnt from is this script. -.-
Yes, I'd like to select the ones which are level 2 (grown ups).
Good luck with the code! I'm sorry I had no idea, what to do there. xP
 
i've been on the verge of finishing my breeding script but i had homework, i started like 2 weeks ago
 
Awesome!
Is there any chance that I could use it or something like that? I'd really love to be able to use it.
Do you use something like genders on your script, or do you use alt images?
 
ok, I did it... I did not test it, because my gender system is a little different, but I'll test soon.

I'm not sure it'll work, but I tried to explain everything for you, so you can change what is necessary

If it works, or if you change it so it works, you can release it in mods forum :D

PHP:
<?php

// Basic Rusnak PHP Adoptables Script configurations
include("inc/functions.php");
include("inc/config.php");

$themeurl = grabanysetting("themeurl");
$links = getlinks();

$ads = getads("any");

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

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

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

// End of basic configurations

$femaleid = $_POST['female'];
$maleid = $_POST['male'];
$breed = $_POST['breed'];
// this two variables will get the female and male ID's from the selection form and the answer if the user has selected the adoptables or not.

// First let's create a page so the users can choose the two adoptables that they want to breed

if($isloggedin == "yes"){ 
// we have to put that in the start of the breeding system, so users that are not logged in cannot see the selection forms

if($breed != 'yes'){
// if the anser if the user has selected the adoptables or not, is different than YES, we have to show the options so the user can select them

// This will start a selection form to select the females
$article_content = $article_content."<p>Select the Two adoptables you want to Breed:</p><p><form method='post'><select name = 'female'>"; 

//This will select all the female adoptables the user has
$result = mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE owner = '$loggedinname' AND gender = 'female'");
$num = mysql_num_rows($result);

// Loop Out code < this will loop so you select all the rows and not just one
$i = 0;
while ($i < $num){
$aid = mysql_result($result,$i,'aid');
$type = mysql_result($result,$i,'type');
$name = mysql_result($result,$i,'name');

$article_content = $article_content."<option value='".$aid."'>".$name." (".$type.")</option>";
//this will display something like that: cute kitty (cat), the name (the type); for each adptable (female) the user has

$i++;
}

$article_content = $article_content."</select><select name='male'>"; //now let's do the same for the males

$result2 = mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE owner = '$loggedinname' AND gender = 'male'");
$num2 = mysql_num_rows($result2);

// Loop Out code
$i2 = 0;
while ($i < $num){
$aid = mysql_result($result2,$i2,'aid');
$type = mysql_result($result2,$i2,'type');
$name = mysql_result($result2,$i2,'name');

$article_content = $article_content."<option value='".$aid."'>".$name." (".$type.")</option>";

$i2++;
}

$article_content = $article_content."</select><input type='hidden' name='breed' value='yes'><input type='submit' value='Breed It'></form>";

// ok now the user has two selection forms to those a female and a male adoptable and when they click Breed It, it will be posted to the variables $_POST['female'] and $_POST['male'], which will be two aid (adoptables ids), and with that ID we can select the information that we need from the database, and breed them

// the hidden input will give us an answer to our question, the user has selected it? and it'll be 'yes'

} // this is the end of if($breed != 'yes'), so now we have to put an ELSE statment, that means that the answer IS yes, and we can proceed with the breeding

else {
// ok, if the user gets here, it means that we have the male and female ID, and with it we can select the informations from the database.

// here you can estabilish what you want.. the adoptables have to be which level to breed? the adoptables have to be the same type? 

// I will do something like that: the adoptables have to be the same type, and level 2 or more. but you can do what you want.. if you have an element system like me, you can estabilish that two water adoptables breed a another water adoptable. or fire and water are incompatible, etc

// first let's get the information we need

$result = mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE aid = '$femaleid'");
// the result should be just one row, so we don't need a loop

$female_type = mysql_result($result,0,'type'); 
// 0 means that we are selecting the very first row, in this case, the only one
$female_name = mysql_result($result,0,'name');
$female_level = mysql_result($result,0,'currentlevel');


$result2 = mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE aid = '$maleid'");
// the result should be just one row, so we don't need a loop

$male_type = mysql_result($result2,0,'type'); 
// 0 means that we are selecting the very first row, in this case, the only one
$male_name = mysql_result($result2,0,'name');
$male_level = mysql_result($result2,0,'currentlevel');

// now we have all we need. let's start the security system, to guarantee that the user has the requirements

if($male_level < 2 OR $female_level < 2){
$article_content = $article_content."Sorry, one of your adoptables don't have the minimum level to breed. Keep training them.";
}
else {
if ($male_type != $female_type){
$article_content = $article_content."Sorry, your adoptables are not the same type, they cannot breed."
}
else{
// ok, we can go one and BREED it, let's make it more real and estabilish a certain chance that the breed will not work. let's say the chance of it to fail, is a formula with the difference of the levels, that way if a adoptable is very old, it will be difficult to breed

$article_content = $article_content."<p>Your adoptables are breeding.</p>"

$rand = rand(1,100);

if($male_level > $female_level){
$failchance = $male_level - $female_level * 3; 
else{
$failchance = $female_level - $male_level * 3;
}
// that way if one is level 2 and the other is level 4, they have a 6% chance of failing, because the formula is higher level - lower level x 3

if($rand < $failchance){
$article_content = $article_content."<p>Result: <b>FAIL</b></p><p>I'm sorry, your adoptables failed at breeding, you can try again later.</p>";
}
else{
$article_content = $article_content."<p>Result: <b>Bred Succesfully</b></p><p>Your new egg is being transferred to you right now.</p>";

// now let's insert the new egg at owned_adoptables

$gender_rand = rand(0,1);

if($gender_rand = 0){
$new_name = $male_name." & ".$female_name."'s Son";
$gender = 'male';
}
else{
$new_name = $male_name." & ".$female_name."'s Daughter";
$gender = 'female';
}

$code = rand(1, 20000);

$result3 = mysql_query("SELECT * FROM ".$prefix."adoptables WHERE type='$male_type'");
$aid=@mysql_result($result3,0,"id"); //The adoptable's ID
$eggimage=$mysql_result($result3,0,'eggimage');

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

mysql_query("INSERT INTO ".$prefix."owned_adoptables VALUES ('', '$male_type', '$new_name','$loggedinname','0','0', '$code', '','$alts','notfortrade','no','$gender')");

$article_content = $article_content."<p><img src='".$eggimage."'><br /><a href='myadopts.php'>Manage ".$new_name." now!</a> You can change its name.</p>";

}

}
}
}

} // this is the end of if($isloggedin == "yes")

else { //this is the else of if($isloggedin == "yes")

$article_content = $article_content."You are not logged in.";

}

// **********************************************************************
// 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
// **********************************************************************
?>
 
Awesome! I have to go now, but I'll test it tomorrow (on my test site).
 
After a few edits (some brackets didn't match) I managed to get it to show, however, it only shows the females on the drop down lists, not the males (the second list is blank.)
Is it possible at $result2/$num2/$i2 are not valid variables?
 
Something amazing - my dad (he knows C and C++ and stuff like that) helped me and I managed to have the whole code working!
PHP:
<?php

// Basic Rusnak PHP Adoptables Script configurations
include("inc/functions.php");
include("inc/config.php");

$themeurl = grabanysetting("themeurl");
$links = getlinks();

$ads = getads("any");

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

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

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

// End of basic configurations

$article_content = $article_title."Breeding System"; 
$article_content = $article_content."<p>Adoptable breeding systems sure aren't easy to make!</p>"; 

$femaleid = $_POST['female'];
$maleid = $_POST['male'];
$breed = $_POST['breed'];
// this two variables will get the female and male ID's from the selection form and the answer if the user has selected the adoptables or not.

// First let's create a page so the users can choose the two adoptables that they want to breed

if ($isloggedin == "yes"){ 
	// we have to put that in the start of the breeding system, so users that are not logged in cannot see the selection forms

	if ($breed != 'yes'){
		// if the anser if the user has selected the adoptables or not, is different than YES, we have to show the options so the user can select them

		// This will start a selection form to select the females
		$article_content = $article_content."<p>Select the Two adoptables you want to Breed:</p><p><form method='post'><select name = 'female'>"; 

		//This will select all the female adoptables the user has
		$result = mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE owner = '$loggedinname' AND gender = 'Female'");
		$num = mysql_num_rows($result);

		// Loop Out code < this will loop so you select all the rows and not just one
		$i = 0;
		while ($i < $num){
			$aid = mysql_result($result,$i,'aid');
			$type = mysql_result($result,$i,'type');
			$name = mysql_result($result,$i,'name');

			$article_content = $article_content."<option value='".$aid."'>".$name." (".$type.")</option>";
			//this will display something like that: cute kitty (cat), the name (the type); for each adptable (female) the user has

			$i++;
		}

		$article_content = $article_content."</select><select name='male'>"; //now let's do the same for the males

		$result2 = mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE owner = '$loggedinname' AND gender = 'Male'");
		$num2 = mysql_num_rows($result2);

		// Loop Out code
		$i2 = 0;
		while ($i2 < $num){
			$aid = mysql_result($result2,$i2,'aid');
			$type = mysql_result($result2,$i2,'type');
			$name = mysql_result($result2,$i2,'name');

			$article_content = $article_content."<option value='".$aid."'>".$name." (".$type.")</option>";

			$i2++;
		}

		$article_content = $article_content."</select><input type='hidden' name='breed' value='yes'><input type='submit' value='Breed It'></form>";

		// ok now the user has two selection forms to those a female and a male adoptable and
                //  when they click Breed It, it will be posted to the variables $_POST['female'] and $_POST['male'], which will be two aid (adoptables ids), 
                //  and with that ID we can select the information that we need from the database, and breed them

		// the hidden input will give us an answer to our question, the user has selected it? and it'll be 'yes'

	} // this is the end of if($breed != 'yes'), so now we have to put an ELSE statment, that means that the answer IS yes, and we can proceed with the breeding

	else {
		// ok, if the user gets here, it means that we have the male and female ID, and with it we can select the informations from the database.
		// here you can estabilish what you want.. the adoptables have to be which level to breed? the adoptables have to be the same type? 
		// I took out the incompatible part, it can be added back in if needed
		// first let's get the information we need

		$result = mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE aid = '$femaleid'");
		// the result should be just one row, so we don't need a loop

		$female_type = mysql_result($result,0,'type'); 
		// 0 means that we are selecting the very first row, in this case, the only one
		$female_name = mysql_result($result,0,'name');
		$female_level = mysql_result($result,0,'currentlevel');


		$result2 = mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE aid = '$maleid'");
		// the result should be just one row, so we don't need a loop

		$male_type = mysql_result($result2,0,'type'); 
		// 0 means that we are selecting the very first row, in this case, the only one
		$male_name = mysql_result($result2,0,'name');
		$male_level = mysql_result($result2,0,'currentlevel');

		// now we have all we need. let's start the security system, to guarantee that the user has the requirements
		
		if ($male_level > 2 AND $female_level > 2){
			//We choose the type!
			$temptype = rand(0, 1);
			if($temptype == "0") {
				$type = $male_type;
				unset($temptype);
			} else {
				$type = $female_type;
				unset($temptype);
			}
			$article_content = $article_content."<p>Your adoptables are breeding.</p>";
		} else { //this is if they can't breed
			$article_content = $article_content."Sorry, one of your adoptables don't have the minimum level to breed. Keep feeding them so they can grow.";	
		} 

		if ($type != "0"){
			$article_content = $article_content."<p>Result: <b>Bred Succesfully</b></p><p>Your new egg is being transferred to you right now. Yay!</p>";

			// now let's insert the new egg at owned_adoptables

			// we're choosing a gender
			$gender_rand = rand(0,1);

			if($gender_rand = 0){
				$new_name = $male_name." & ".$female_name."'s Son";
				$gender = 'male';
				unset($gender_rand);
			}
			else{
				$new_name = $male_name." & ".$female_name."'s Daughter";
				$gender = 'female';
				unset($gender_rand);
			}

			// now we're choosing the code
			$code = rand(1, 20000);

			$result3 = mysql_query("SELECT * FROM ".$prefix."adoptables WHERE type='$male_type'");
			$aid = mysql_result($result3,0,"id"); //The adoptable's ID
			$eggimage = mysql_result($result3,0,"eggimage");

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

			mysql_query("INSERT INTO ".$prefix."owned_adoptables VALUES ('', '$type', '$new_name','$loggedinname','0','0', '$code', '','$alts','notfortrade','no','$gender')");

			$article_content = $article_content."<p><img src='".$eggimage."'><br /><a href='myadopts.php'>Manage ".$new_name." now!</a> You can change its name to your liking.</p>";

		}

		//uh, this is just here because we need an else, right?
		else {
			break;
		}

	} //this bracket ends the else where we find the male/female id's
}// this is the end of if($isloggedin == "yes")

else { //this is the else of if($isloggedin == "yes")

	$article_content = $article_content."You are not logged in. Please log in to breed.";

}

// **********************************************************************
// 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
// **********************************************************************
?>
The only problem is that it doesn't actually create the adoptable. That's a problem, but we're making progress. :D
 
Don't forget to secure your variables. Anything coming in from the user needs to be secured, otherwise your site can easily be hacked.

For:

PHP:
$femaleid = $_POST['female'];
$maleid = $_POST['male'];
$breed = $_POST['breed'];

I recommend:

PHP:
$femaleid = $_POST['female'];
$maleid = $_POST['male'];
$breed = $_POST['breed'];

$femaleid = secure($femaleid);
$maleid = secure($maleid);
$breed = secure($breed);

That will run the built in security on the variables before you use them in the database. Without this your site can be hacked by someone entering in malicious data. :)
 
Okay, I'll change that.
Have you any ideas on how to get it working so it inserts the adoptable properly?
 
Make sure that the number of columns in this line:

PHP:
mysql_query("INSERT INTO ".$prefix."owned_adoptables VALUES ('', '$type', '$new_name','$loggedinname','0','0', '$code', '','$alts','notfortrade','no','$gender')");

is the same as the number of columns in your owned_adoptables table in your database. If they don't match up then the adoptable will never be inserted. :)
 
Okay, let me see
PHP:
'','$type','$new_name','$loggedinname','0','0','$code','','$alts','notfortrade','no','$gender'
The table is
aid, type, name, owner, currentlevel, totalclicks, code, imageurl, usealternates, tradestatus, isfrozen, gender... date.
I cannot see how I missed that. xP I'll edit and see if it works.

I now did that, but it tells me this at the top of the page (it still displays the rest, though).
Code:
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 4 on MySQL result index 22 in /home/pixelpup/public_html/twig3/adoptables/breeding.php on line 76

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 4 on MySQL result index 22 in /home/pixelpup/public_html/twig3/adoptables/breeding.php on line 77

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 4 on MySQL result index 22 in /home/pixelpup/public_html/twig3/adoptables/breeding.php on line 78
 
Here is my updated version. I'm doing OK - the code is free of syntax errors and it defines the variables correctly, but it won't insert into the table at all!
If anyone is nice enough to help, it is supposed to insert the adoptable on line 195.
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");

$themeurl = grabanysetting("themeurl");

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

$links = getlinks();

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

$ads = getads("any");

// **********************************************************************
// 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
// **********************************************************************


$article_content = $article_title."Breeding System"; 
$article_content = $article_content."<p>Adoptable breeding systems sure aren't easy to make! I wish that this would work!</p>"; 

$femaleid = $_POST['female'];
$maleid = $_POST['male'];
$breed = $_POST['breed'];

$femaleid = secure($femaleid);
$maleid = secure($maleid);
$breed = secure($breed); 

// this two variables will get the female and male ID's from the selection form and the answer if the user has selected the adoptables or not.

// First let's create a page so the users can choose the two adoptables that they want to breed

if ($isloggedin == "yes"){ 
    // we have to put that in the start of the breeding system, so users that are not logged in cannot see the selection forms

    if ($breed != 'yes'){
        // if the anser if the user has selected the adoptables or not, is different than YES, we have to show the options so the user can select them

        // This will start a selection form to select the females
        $article_content = $article_content."<p>Select the Two adoptables you want to Breed:</p><p><form method='post'><select name = 'female'>"; 

        //This will select all the female adoptables the user has
        $result = mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE owner = '$loggedinname' AND gender = 'Female'");
        $num = mysql_num_rows($result);

        // Loop Out code < this will loop so you select all the rows and not just one
        $i = 0;
        while ($i < $num){
            $aid = mysql_result($result,$i,'aid');
            $type = mysql_result($result,$i,'type');
            $name = mysql_result($result,$i,'name');

            $article_content = $article_content."<option value='".$aid."'>".$name." (".$type.")</option>";
            //this will display something like that: cute kitty (cat), the name (the type); for each adptable (female) the user has

            $i++;
        }

        $article_content = $article_content."</select><select name='male'>"; //now let's do the same for the males

        $result2 = mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE owner = '$loggedinname' AND gender = 'Male'");
        $num2 = mysql_num_rows($result2);

        // Loop Out code
        $i2 = 0;
        while ($i2 < $num){
            $aid2 = mysql_result($result2,$i2,'aid');
            $type2 = mysql_result($result2,$i2,'type');
            $name2 = mysql_result($result2,$i2,'name');

            $article_content = $article_content."<option value='".$aid2."'>".$name2." (".$type2.")</option>";

            $i2++;
        }

        $article_content = $article_content."</select><input type='hidden' name='breed' value='yes'><input type='submit' value='Breed It'></form>";

        // ok now the user has two selection forms to those a female and a male adoptable and when they click Breed It,
        //   it will be posted to the variables $_POST['female'] and $_POST['male'], which will be two aid (adoptables ids), and with
        //   that ID we can select the information that we need from the database, and breed them

        // the hidden input will give us an answer to our question, the user has selected it? and it'll be 'yes'

    } // this is the end of if($breed != 'yes'), so now we have to put an ELSE statment, that means that the answer IS yes, and we can proceed with the breeding

    else {
        // ok, if the user gets here, it means that we have the male and female ID, and with it we can select the informations from the database.
        // here you can estabilish what you want.. the adoptables have to be which level to breed? the adoptables have to be the same type? 
        // I took out the incompatible part, it can be added back in if needed
        // first let's get the information we need

        $result = mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE aid = '$femaleid'");
        // the result should be just one row, so we don't need a loop

        $female_type = mysql_result($result,0,'type'); 
        // 0 means that we are selecting the very first row, in this case, the only one
        $female_name = mysql_result($result,0,'name');
        $female_level = mysql_result($result,0,'currentlevel');


        $result2 = mysql_query("SELECT * FROM ".$prefix."owned_adoptables WHERE aid = '$maleid'");
        // the result should be just one row, so we don't need a loop

        $male_type = mysql_result($result2,0,'type'); 
        // 0 means that we are selecting the very first row, in this case, the only one
        $male_name = mysql_result($result2,0,'name');
        $male_level = mysql_result($result2,0,'currentlevel');

        // now we have all we need. let's start the security system, to guarantee that the user has the requirements
		
        if ($male_level < 2 OR $female_level < 2){ //this is if they can't breed
            $article_content = $article_content."Sorry, one of your adoptables don't have the minimum level to breed. Keep feeding them so they can grow.";    
        } 

        else {
            //We choose the type!
            $temptype = rand(0, 1);
            if($temptype == "0") {
                $type = $male_type;
                unset($temptype);
            } else {
                $type = $female_type;
                unset($temptype);
            }
            $article_content = $article_content."<p>Your adoptables are breeding.</p>";
         
            if ($type != "0"){
               $article_content = $article_content."<p>Result: <b>Bred Succesfully</b></p><p>Your new egg is being transferred to you right now. Yay!</p>";

               // now let's insert the new egg at owned_adoptables

               // we're choosing a gender
               $gender_rand = rand(0,1);

               if($gender_rand = 0){
                   $new_name = $male_name." & ".$female_name."'s Son";
                   $gender = 'male';
                   unset($gender_rand);
                }
               else{
                   $new_name = $male_name." & ".$female_name."'s Daughter";
                   $gender = 'female';
                   unset($gender_rand);
                }

               // now we're choosing the code
               $code = rand(1, 20000);

               $result3 = mysql_query("SELECT * FROM ".$prefix."adoptables WHERE type='$male_type'");
               $aid = mysql_result($result3,0,"id"); //The adoptable's ID
               $eggimage = mysql_result($result3,0,"eggimage");

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

               // and the date comes in here too
               $date = date("F jS, Y");   
               
               $name = $new_name;

               mysql_query("INSERT INTO ".$prefix."owned_adoptables VALUES ('', '$type', '$name','$loggedinname','0','0', '$code', '','$alts','notfortrade','no','$gender','$date')");

               $article_content = $article_content."<p><img src='".$eggimage."'><br /><a href='myadopts.php'>Manage ".$name." now!</a>
               <br> It's type is ".$type." and it was born on ".$date."! You can change its name to your liking.</p>";

            } // if our type is not equal to zero, this is where we continue. this is the end of the continuation.
        } // we end the place where it goes on if the levels are ok
    } //this bracket ends the else where we find the male/female id's
}// this is the end of if($isloggedin == "yes")

else { //this is the else of if($isloggedin == "yes")

    $article_content = $article_content."You are not logged in. Please log in to breed.";

}


// **********************************************************************
// 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
// **********************************************************************



?>
 
you use $name = $new_name; But just looking over it quickly I don't see where $new_name is defined.

Sea
 
Here :D
PHP:
if($gender_rand = 0){
                $new_name = $male_name." & ".$female_name."'s Son";
                $gender = 'male';
                unset($gender_rand);
            }
            else{
                $new_name = $male_name." & ".$female_name."'s Daughter";
                $gender = 'female';
                unset($gender_rand);
            }
It works on the code, producing something to the like of this at the end:
Code:
Manage Ik & Random's Daughter now! It's type is Jinx and it was born on October 27th, 2009! You can change its name to your liking.
I don't believe that that is the problem, I think that it's not inserting it into the database correctly.
 

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

Latest Posts

Top