Jump to content
MakeWebGames

Call to undefined function


Lilith

Recommended Posts

Ok, so Im trying to take a farming mod and develop a new mod from it. (something more interesting involving collecting rent from tenants)

But, I keep getting the error

Fatal error: Call to undefined function animals() in /home/battlefo/public_html/farm.php on line 9

I have researched switch, case, functions ect with the normal sites, but cant seem to identify the error. Everything on google for Call to undefined function is followed by my_sql_connect for wordpress etc dealing with not being able to connect to the database. So, Im pretty stumped here.

Can someone explain to me why you would use the switch($_GET['action']) with listed cases, and why I'm seeing this error?

 

<?php
include("globals.php");

switch($_GET['action'])
                      {
case 'barnfi' : barnfi(); break;
case 'barnbou' : barnbou(); break;
case 'upgrade': upgrade(); break;
case 'animals': animals(); break;
case 'farm': farm(); break;
case 'land': land(); break;
case 'landb': landb(); break;
default: index();
        }
function index()

//Blah Blah Blah///
//function that is being sited in the error//

function animals()
        {
global $ir, $c, $userid, $h, $db;
}
if ($farmplots>0)
{
print "[b]Sarah:[/b] Hi! Welcome to the managment area of your ofice. Here you can find the tenants that you can let move in and collect rent from! You pay the aplicible moving fees for these tenants, then you pay the maintenence guy on your building his wages and eventually you'll start making money back from their rent. Cool huh? But if you fail to pay the maintence man, your tenants will leave!


[b]Sarah:[/b] So who would you like?

";
$arraypick = mysql_query("select * from tenants");
}
print "<table><tr><td>[b]Tenant name[/b]</td><td>[b]Tenant Moving Fees[/b]</td><td>[b]Maintenence Costs[/b]</td><td>[b]Rent Paid[/b]</td><td>[b]Number of Applicants[/b]</td><td>[b]Approve[/b]</td></tr>";
while ($display = mysql_query($arraypick))
{
print "<tr><td>".$display['type']."</td><td><center>'".number_format($display['cost'])."'</center></td><td><center>".$display['rent']." ".$display['instock']."</center></td><td><center>[url='farm.php?action=animals&step=buyanimal&id=".$display[']Buy[/url]</center></td></tr>";
}
print "</table>

";

if ($step == "buyanimal")
{
$animload = mysql_query("select * from farm_anim_listdb where id='$id'");
$anim = mysql_query($animload);
$animload = mysql_query("select * from tenants where owner=$userid'");
$animnum = mysql_query($animload)*10;
$total = $animnum;
}
if ($total > ($farmplots*10))
{
print "You do not have enough space to house this tenant.";
     }
elseif (($ir['money']) < $anim['cost'])
      {
print "You cannot afford this.";
     }
else
   {
print "[b]Sarah:[/b] I'll send that tenant right over!";
$rem_money = mysql_query("Update user set money=money-".$anim['cost']." where userid=$userid'");
$add_tenant = mysql_query("Insert into farm_animdb (id,owner,animalname,cost,matureage,prod_name,prod_amount,assist_need,food_need,water_need) values ('',$userid','".$anim['animalname']."','".$anim['cost']."','".$anim['matureage']."','".$anim['prod_name']."','".$anim['prod_amount']."','".$anim['assist_need']."','".$anim['food_need']."','".$anim['water_need']."')");
$red_stock = mysql_query("update farm_anim_listdb set instock=instock-1 where id='".$anim['id']."'");
}
}
$h->endpage();
exit;
//blah blah blah//
Link to comment
Share on other sites

OK. I'm not too sure about this but I think it might work.

First of all:

switch($_GET['action']) - Now. As I can tell by the first word. You are switching something, that doesn't have a meaning to switch. I'm not exactly sure what you are trying to upgrade this farming file, but something should be put in front of it. If this doesn't work, please get back on this with me.

Secondly:

function animals() { global $ir, $c, $userid, $h, $db; } - What I can see straight away, your already ending your function. ( { Opening the function || } Closing the function (P.S: I Don't mean to sound sarcastic)).

Third:

$????? - Look ($farmplots) no were in the code, can I see $farmplots assigning to anything.

Also, just for prefrences. When using some like SELECT - FROM - WHERE. Make it caps. :P

Link to comment
Share on other sites

Thanks for the tips,

to answer some of what you have noticed, this file is like 6 pages long with multiple functions. I didn't feel the need to post the entire file and bore everyone to death, so I only included the pertinent parts.

You don't sound sarcastic, as this is the first time I have messed with functions, and Ive only been coding for around 4 months. I learn fast, but Im still missing pieces.

($farmplots) is defined and used in the //blah blah blah/// that I edited out for making the post shorter.

The farming file I'm changing is located in the free mods section WAYYYY back. It never did work properly, but the concept behind it was very close to the mod I wanted to create, so I figured it was a good place to start. This function is the only thing not working in it yet. After I get it functioning, Ill change the labels to better reflect what the mod is. for example barn=rental licence, animals=tenants, land=apartment building, etc. After the player makes some investment into this mod, it will return a rental income based on how much they have invested, and how well they have maintained their apartments.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...