Jump to content
MakeWebGames

Fatal Error


War_Hero

Recommended Posts

Hi all. :)

I'm getting a bit annoyed with this error I keep getting:

Fatal error: Call to undefined function index() in /usr/home/**********/domains/globalconflict2250.co.uk/public_html/cyberbank.php on line 28

This is my code:

<?php
include "globals.php";
$ir['cybermoney'] = floor($ir['cybermoney']);
if($ir['jail'] or $ir['hospital']) { die("This page cannot be accessed while in jail or hospital."); }
if($ir['location'] < 3) { die("You have to be in Neptune to access the Cyber Bank."); }

$sql = ("SELECT * FROM `researchfund`");
$query = $db->query($sql);
$row = $db->fetch_row($query);

if($row['fund'] >= 35000000 OR $ir['screen'] == 1)
{

print "<h3>Cyber Bank</h3>";
if($ir['cybermoney']>-1)
{
switch($_GET['action'])
{
case "deposit":
deposit();
break;

case "withdraw":
withdraw();
break;

default:
index();
break;
}

}
else
{
if(isset($_GET['buy']))
{
if($ir['money']>9999999)
{
print "Congratulations, you bought a bank account for £10,000,000!

[url='cyberbank.php']Start using my account[/url]";
$db->query("UPDATE users SET money=money-10000000,cybermoney=0 WHERE userid=$userid");
}
else
{
print "You do not have enough money to open an account.
[url='explore.php']Back to town...[/url]";
}
}
else
{
print "Open a bank account today, just £10,000,000!

[url='cyberbank.php?buy']> Yes, sign me up![/url]";
}
}
function index()
{
global $db,$ir,$c,$userid,$h;
print "\n[b]You currently have £{$ir['cybermoney']} in the bank.[/b]

At the end of each day, your bank balance will go up by 10%.

<table width='75%' border='2'> <tr> <td width='50%'>[b]Deposit Money[/b]

It will cost you 15% of the money you deposit, rounded up. The maximum fee is £1,500,000.<form action='cyberbank.php?action=deposit' method='post'>
Amount: <input type='text' name='deposit' value='{$ir['money']}' />

<input type='submit' value='Deposit' /></form></td> <td>
[b]Withdraw Money[/b]

It will cost you 7.5% of the money you withdraw, rounded up. The maximum fee is £750,000.<form action='cyberbank.php?action=withdraw' method='post'>
Amount: <input type='text' name='withdraw' value='{$ir['cybermoney']}' />

<input type='submit' value='Withdraw' /></form></td> </tr> </table>";
}
function deposit()
{
global $db,$ir,$c,$userid,$h;
$_POST['deposit']=abs((float) $_POST['deposit']);
if($_POST['deposit'] > $ir['money'])
{
print "You do not have enough money to deposit this amount.";
}
else
{
$fee=ceil($_POST['deposit']*15/100);
if($fee > 1500000) { $fee=1500000; }
$gain=$_POST['deposit']-$fee;
$ir['cybermoney']+=$gain;
$db->query("UPDATE users SET cybermoney=cybermoney+$gain, money=money-{$_POST['deposit']} where userid=$userid");
print "You hand over £{$_POST['deposit']} to be deposited, 

after the fee is taken (£$fee), £$gain is added to your account. 

[b]You now have £{$ir['cybermoney']} in the Cyber Bank.[/b]

[url='cyberbank.php']> Back[/url]";
}
}
function withdraw()
{
global $db,$ir,$c,$userid,$h;
$_POST['withdraw']=abs((float) $_POST['withdraw']);
if($_POST['withdraw'] > $ir['cybermoney'])
{
print "You do not have enough banked money to withdraw this amount.";
}
else
{
$fee=ceil($_POST['withdraw']*75/1000);
if($fee > 750000) { $fee=750000; }
$gain=$_POST['withdraw']-$fee;
$ir['cybermoney']-=$gain;
$db->query("UPDATE users SET cybermoney=cybermoney-$gain, money=money+$gain where userid=$userid");
print "You ask to withdraw £$gain, 

the teller hands it over after she takes the bank fees. 

[b]You now have £{$ir['cybermoney']} in the Cyber Bank.[/b]

[url='cyberbank.php']> Back[/url]";
}
}
}

elseif($row['fund'] < 35000000 AND $ir['screen'] == 0)
{
die("You need to be screened first before you can access the Holiday Gym. Go <a href = 'screening.php' />HERE</a> to get screened.");
}

$h->endpage();
?>

 

This is the code around line 28:

print "<h3>Cyber Bank</h3>";
if($ir['cybermoney']>-1)
{
switch($_GET['action'])
{
case "deposit":
deposit();
break;

case "withdraw":
withdraw();
break;

default:
index();
break;
}

 

with index(); being line 28.

 

It was working fine until I added this bit in:

$sql = ("SELECT * FROM `researchfund`");
$query = $db->query($sql);
$row = $db->fetch_row($query);

if($row['fund'] >= 35000000 OR $ir['screen'] == 1)
{

 

so I'm not sure how to fix it. I've thought about how to fix it, but whatever I try doesn't seem to work. :(

Any help will be much appreciated. I'm still a newbie at PHP and all help will help me learn and understand where I went wrong and how I can fix it. :)

Link to comment
Share on other sites

Re: Fatal Error

 

<?php
include "globals.php";
$ir['cybermoney'] = floor($ir['cybermoney']);
if($ir['jail'] or $ir['hospital']) { die("This page cannot be accessed while in jail or hospital."); }
if($ir['location'] < 3) { die("You have to be in Neptune to access the Cyber Bank."); }

$sql = ("SELECT * FROM `researchfund`");
$query = $db->query($sql);
$row = $db->fetch_row($query);

if($row['fund'] >= 35000000 OR $ir['screen'] == 1)
{

print "<h3>Cyber Bank</h3>";
if($ir['cybermoney']>-1)
{
switch($_GET['action'])
{
case "deposit":
deposit();
break;

case "withdraw":
withdraw();
break;

default:
index();
break;
}
else
{
if(isset($_GET['buy']))
{
if($ir['money']>9999999)
{
print "Congratulations, you bought a bank account for £10,000,000!

[url='cyberbank.php']Start using my account[/url]";
$db->query("UPDATE users SET money=money-10000000,cybermoney=0 WHERE userid=$userid");
}
else
{
print "You do not have enough money to open an account.
[url='explore.php']Back to town...[/url]";
}
}
else
{
print "Open a bank account today, just £10,000,000!

[url='cyberbank.php?buy']> Yes, sign me up![/url]";
}
}
function index()
{
global $db,$ir,$c,$userid,$h;
print "\n[b]You currently have £{$ir['cybermoney']} in the bank.[/b]

At the end of each day, your bank balance will go up by 10%.

<table width='75%' border='2'> <tr> <td width='50%'>[b]Deposit Money[/b]

It will cost you 15% of the money you deposit, rounded up. The maximum fee is £1,500,000.<form action='cyberbank.php?action=deposit' method='post'>
Amount: <input type='text' name='deposit' value='{$ir['money']}' />

<input type='submit' value='Deposit' /></form></td> <td>
[b]Withdraw Money[/b]

It will cost you 7.5% of the money you withdraw, rounded up. The maximum fee is £750,000.<form action='cyberbank.php?action=withdraw' method='post'>
Amount: <input type='text' name='withdraw' value='{$ir['cybermoney']}' />

<input type='submit' value='Withdraw' /></form></td> </tr> </table>";
}
function deposit()
{
global $db,$ir,$c,$userid,$h;
$_POST['deposit']=abs((float) $_POST['deposit']);
if($_POST['deposit'] > $ir['money'])
{
print "You do not have enough money to deposit this amount.";
}
else
{
$fee=ceil($_POST['deposit']*15/100);
if($fee > 1500000) { $fee=1500000; }
$gain=$_POST['deposit']-$fee;
$ir['cybermoney']+=$gain;
$db->query("UPDATE users SET cybermoney=cybermoney+$gain, money=money-{$_POST['deposit']} where userid=$userid");
print "You hand over £{$_POST['deposit']} to be deposited, 

after the fee is taken (£$fee), £$gain is added to your account. 

[b]You now have £{$ir['cybermoney']} in the Cyber Bank.[/b]

[url='cyberbank.php']> Back[/url]";
}
}
function withdraw()
{
global $db,$ir,$c,$userid,$h;
$_POST['withdraw']=abs((float) $_POST['withdraw']);
if($_POST['withdraw'] > $ir['cybermoney'])
{
print "You do not have enough banked money to withdraw this amount.";
}
else
{
$fee=ceil($_POST['withdraw']*75/1000);
if($fee > 750000) { $fee=750000; }
$gain=$_POST['withdraw']-$fee;
$ir['cybermoney']-=$gain;
$db->query("UPDATE users SET cybermoney=cybermoney-$gain, money=money+$gain where userid=$userid");
print "You ask to withdraw £$gain, 

the teller hands it over after she takes the bank fees. 

[b]You now have £{$ir['cybermoney']} in the Cyber Bank.[/b]

[url='cyberbank.php']> Back[/url]";
}
}
}

elseif($row['fund'] < 35000000 AND $ir['screen'] == 0)
{
die("You need to be screened first before you can access the Holiday Gym. Go <a href = 'screening.php' />HERE</a> to get screened.");
}

$h->endpage();
?>

 

Try that mate

Link to comment
Share on other sites

Re: Fatal Error

Thank you for replying.

But I now get this error:

Parse error: syntax error, unexpected T_ELSE in /usr/home/********/domains/globalconflict2250.co.uk/public_html/cyberbank.php on line 31

:(

I don't really like ELSES because I've had some trouble with them before. :-P

Link to comment
Share on other sites

Re: Fatal Error

Try this

 

<?php
include "globals.php";
$ir['cybermoney'] = floor($ir['cybermoney']);
if($ir['jail'] or $ir['hospital']) { die("This page cannot be accessed while in jail or hospital."); }
if($ir['location'] < 3) { die("You have to be in Neptune to access the Cyber Bank."); }

$sql = ("SELECT * FROM `researchfund`");
$query = $db->query($sql);
$row = $db->fetch_row($query);

if($row['fund'] >= 35000000 OR $ir['screen'] == 1)
{

print "<h3>Cyber Bank</h3>";
if($ir['cybermoney']>-1)
{
switch($_GET['action'])
{
case "deposit":
deposit();
break;

case "withdraw":
withdraw();
break;

default:
index();
break;
}
else
{
if(isset($_GET['buy']))
}
if($ir['money']>9999999)
{
print "Congratulations, you bought a bank account for £10,000,000!

[url='cyberbank.php']Start using my account[/url]";
$db->query("UPDATE users SET money=money-10000000,cybermoney=0 WHERE userid=$userid");
}
else
{
print "You do not have enough money to open an account.
[url='explore.php']Back to town...[/url]";
}
}
else
{
print "Open a bank account today, just £10,000,000!

[url='cyberbank.php?buy']> Yes, sign me up![/url]";
}
}
function index()
{
global $db,$ir,$c,$userid,$h;
print "\n[b]You currently have £{$ir['cybermoney']} in the bank.[/b]

At the end of each day, your bank balance will go up by 10%.

<table width='75%' border='2'> <tr> <td width='50%'>[b]Deposit Money[/b]

It will cost you 15% of the money you deposit, rounded up. The maximum fee is £1,500,000.<form action='cyberbank.php?action=deposit' method='post'>
Amount: <input type='text' name='deposit' value='{$ir['money']}' />

<input type='submit' value='Deposit' /></form></td> <td>
[b]Withdraw Money[/b]

It will cost you 7.5% of the money you withdraw, rounded up. The maximum fee is £750,000.<form action='cyberbank.php?action=withdraw' method='post'>
Amount: <input type='text' name='withdraw' value='{$ir['cybermoney']}' />

<input type='submit' value='Withdraw' /></form></td> </tr> </table>";
}
function deposit()
{
global $db,$ir,$c,$userid,$h;
$_POST['deposit']=abs((float) $_POST['deposit']);
if($_POST['deposit'] > $ir['money'])
}
print "You do not have enough money to deposit this amount.";
{
}
else
{
$fee=ceil($_POST['deposit']*15/100);
if($fee > 1500000) { $fee=1500000; }
$gain=$_POST['deposit']-$fee;
$ir['cybermoney']+=$gain;
$db->query("UPDATE users SET cybermoney=cybermoney+$gain, money=money-{$_POST['deposit']} where userid=$userid");
print "You hand over £{$_POST['deposit']} to be deposited, 

after the fee is taken (£$fee), £$gain is added to your account. 

[b]You now have £{$ir['cybermoney']} in the Cyber Bank.[/b]

[url='cyberbank.php']> Back[/url]";
}
}
function withdraw()
{
global $db,$ir,$c,$userid,$h;
$_POST['withdraw']=abs((float) $_POST['withdraw']);
if($_POST['withdraw'] > $ir['cybermoney'])
}
print "You do not have enough banked money to withdraw this amount.";
{
}
else
{
$fee=ceil($_POST['withdraw']*75/1000);
if($fee > 750000) { $fee=750000; }
$gain=$_POST['withdraw']-$fee;
$ir['cybermoney']-=$gain;
$db->query("UPDATE users SET cybermoney=cybermoney-$gain, money=money+$gain where userid=$userid");
print "You ask to withdraw £$gain, 

the teller hands it over after she takes the bank fees. 

[b]You now have £{$ir['cybermoney']} in the Cyber Bank.[/b]

[url='cyberbank.php']> Back[/url]";
}
{
}

elseif($row['fund'] < 35000000 AND $ir['screen'] == 0)
{
die("You need to be screened first before you can access the Holiday Gym. Go <a href = 'screening.php' />HERE</a> to get screened.");
}

$h->endpage();
?>
Link to comment
Share on other sites

Re: Fatal Error

If that doesent work then try this

 

<?php
include "globals.php";
$ir['cybermoney'] = floor($ir['cybermoney']);
if($ir['jail'] or $ir['hospital']) { die("This page cannot be accessed while in jail or hospital."); }
if($ir['location'] < 3) { die("You have to be in Neptune to access the Cyber Bank."); }

$sql = ("SELECT * FROM `researchfund`");
$query = $db->query($sql);
$row = $db->fetch_row($query);

if($row['fund'] >= 35000000 OR $ir['screen'] == 1)
{

print "<h3>Cyber Bank</h3>";
if($ir['cybermoney']>-1)
}
switch($_GET['action'])
{
case "deposit":
deposit();
break;

case "withdraw":
withdraw();
break;

default:
index();
break;
}
else
{
if(isset($_GET['buy']))
}
if($ir['money']>9999999)
{
print "Congratulations, you bought a bank account for £10,000,000!

[url='cyberbank.php']Start using my account[/url]";
$db->query("UPDATE users SET money=money-10000000,cybermoney=0 WHERE userid=$userid");
}
else
{
print "You do not have enough money to open an account.
[url='explore.php']Back to town...[/url]";
}
else
{
print "Open a bank account today, just £10,000,000!

[url='cyberbank.php?buy']> Yes, sign me up![/url]";
}
function index()
{
global $db,$ir,$c,$userid,$h;
print "\n[b]You currently have £{$ir['cybermoney']} in the bank.[/b]

At the end of each day, your bank balance will go up by 10%.

<table width='75%' border='2'> <tr> <td width='50%'>[b]Deposit Money[/b]

It will cost you 15% of the money you deposit, rounded up. The maximum fee is £1,500,000.<form action='cyberbank.php?action=deposit' method='post'>
Amount: <input type='text' name='deposit' value='{$ir['money']}' />

<input type='submit' value='Deposit' /></form></td> <td>
[b]Withdraw Money[/b]

It will cost you 7.5% of the money you withdraw, rounded up. The maximum fee is £750,000.<form action='cyberbank.php?action=withdraw' method='post'>
Amount: <input type='text' name='withdraw' value='{$ir['cybermoney']}' />

<input type='submit' value='Withdraw' /></form></td> </tr> </table>";
}
function deposit()
{
global $db,$ir,$c,$userid,$h;
$_POST['deposit']=abs((float) $_POST['deposit']);
if($_POST['deposit'] > $ir['money'])
}
print "You do not have enough money to deposit this amount.";
{
}
else
{
$fee=ceil($_POST['deposit']*15/100);
if($fee > 1500000) { $fee=1500000; }
$gain=$_POST['deposit']-$fee;
$ir['cybermoney']+=$gain;
$db->query("UPDATE users SET cybermoney=cybermoney+$gain, money=money-{$_POST['deposit']} where userid=$userid");
print "You hand over £{$_POST['deposit']} to be deposited, 

after the fee is taken (£$fee), £$gain is added to your account. 

[b]You now have £{$ir['cybermoney']} in the Cyber Bank.[/b]

[url='cyberbank.php']> Back[/url]";
{
}
function withdraw()
{
global $db,$ir,$c,$userid,$h;
$_POST['withdraw']=abs((float) $_POST['withdraw']);
if($_POST['withdraw'] > $ir['cybermoney'])
}
print "You do not have enough banked money to withdraw this amount.";
{
}
else
{
$fee=ceil($_POST['withdraw']*75/1000);
if($fee > 750000) { $fee=750000; }
$gain=$_POST['withdraw']-$fee;
$ir['cybermoney']-=$gain;
$db->query("UPDATE users SET cybermoney=cybermoney-$gain, money=money+$gain where userid=$userid");
print "You ask to withdraw £$gain, 

the teller hands it over after she takes the bank fees. 

[b]You now have £{$ir['cybermoney']} in the Cyber Bank.[/b]

[url='cyberbank.php']> Back[/url]";
}
{
}

elseif($row['fund'] < 35000000 AND $ir['screen'] == 0)
{
die("You need to be screened first before you can access the Holiday Gym. Go <a href = 'screening.php' />HERE</a> to get screened.");
}

$h->endpage();
?>
Link to comment
Share on other sites

Re: Fatal Error

Hmm. That still doesn't work. :(

I get this error:

Parse error: syntax error, unexpected '}' in /usr/home/********/domains/globalconflict2250.co.uk/public_html/cyberbank.php on line 16.

This was for the second code.

I get this error for the first one:

Parse error: syntax error, unexpected T_ELSE in /usr/home/*********/domains/globalconflict2250.co.uk/public_html/cyberbank.php on line 31

I'm having a look at it as well to see what's wrong.

Link to comment
Share on other sites

Re: Fatal Error

I would help you with this, but tbh the code is a complete mess, I started to look over it, and i can't work out what the hell you are trying to do..

I got to about here

 

if($row['fund'] >= 35000000 OR $ir['screen'] == 1)
{

print "<h3>Cyber Bank</h3>";
if($ir['cybermoney']>-1)
}

 

and gave up, there's a random if statement just sitting there...

I think your best bet is to start again, and learn how to use if / else correctly..

Link to comment
Share on other sites

Re: Fatal Error

Oh no. I didn't code the Cyber Bank. It came with the V2 package. ;)

I know how to use else/if, just got a bit confused when I was trying to add in that particular bit. I've got it to work now, just needed to tweak some of the code. :)

I might just go back and neaten up the Cyber Bank code so it's much easier to read. :)

Link to comment
Share on other sites

Re: Fatal Error

 

Oh no. I didn't code the Cyber Bank. It came with the V2 package. ;)

I know how to use else/if, just got a bit confused when I was trying to add in that particular bit. I've got it to work now, just needed to tweak some of the code. :)

I might just go back and neaten up the Cyber Bank code so it's much easier to read. :)

No surprise, mccodes can be a mess, confused me just trying to read it. :lol:

Link to comment
Share on other sites

Re: Fatal Error

I agree with you there. I now see why some people say it's not good to learn PHP from MCCODES.....

What also confused me with that particular IF/ELSE statement was where to put it because of the functions. But I managed my way round it. I might experience an issue similar to it when I edit my travel mod... (I'm doing a bit of editing to a few of my pages to incorporate a new mod I made.) :)

Link to comment
Share on other sites

Re: Fatal Error

Yea pog it's hidden until the 5th city.

 

<?php
include "globals.php";
print "<h3>Cyber Bank</h3>";
if($ir['cybermoney']>-1)
{
switch($_GET['action'])
{
case "deposit":
deposit();
break;

case "withdraw":
withdraw();
break;

default:
index();
break;
}

}
else
{
if(isset($_GET['buy']))
{
if($ir['money']>9999999)
{
print "Congratulations, you bought a bank account for \$10,000,000!

[url='cyberbank.php']Start using my account[/url]";
$db->query("UPDATE users SET money=money-10000000,cybermoney=0 WHERE userid=$userid");
}
else
{
print "You do not have enough money to open an account.
[url='explore.php']Back to town...[/url]";
}
}
else
{
print "Open a bank account today, just \$10,000,000!

[url='cyberbank.php?buy']> Yes, sign me up![/url]";
}
}
function index()
{
global $db,$ir,$c,$userid,$h;
print "\n[b]You currently have \${$ir['cybermoney']} in the bank.[/b]

At the end of each day, your bank balance will go up by 7%.

<table width='75%' border='2'> <tr> <td width='50%'>[b]Deposit Money[/b]

It will cost you 15% of the money you deposit, rounded up. The maximum fee is \$1,500,000.<form action='cyberbank.php?action=deposit' method='post'>
Amount: <input type='text' name='deposit' value='{$ir['money']}' />

<input type='submit' value='Deposit' /></form></td> <td>
[b]Withdraw Money[/b]

It will cost you 7.5% of the money you withdraw, rounded up. The maximum fee is \$750,000.<form action='cyberbank.php?action=withdraw' method='post'>
Amount: <input type='text' name='withdraw' value='{$ir['cybermoney']}' />

<input type='submit' value='Withdraw' /></form></td> </tr> </table>";
}
function deposit()
{
global $db,$ir,$c,$userid,$h;
$_POST['deposit']=abs((int) $_POST['deposit']);
if($_POST['deposit'] > $ir['money'])
{
print "You do not have enough money to deposit this amount.";
}
else
{
$fee=ceil($_POST['deposit']*15/100);
if($fee > 1500000) { $fee=1500000; }
$gain=$_POST['deposit']-$fee;
$ir['cybermoney']+=$gain;
$db->query("UPDATE users SET cybermoney=cybermoney+$gain, money=money-{$_POST['deposit']} where userid=$userid");
print "You hand over \${$_POST['deposit']} to be deposited, 

after the fee is taken (\$$fee), \$$gain is added to your account. 

[b]You now have \${$ir['cybermoney']} in the Cyber Bank.[/b]

[url='cyberbank.php']> Back[/url]";
}
}
function withdraw()
{
global $ir,$c,$userid,$h,$db;
$_POST['withdraw']=abs((int) $_POST['withdraw']);
if($_POST['withdraw'] > $ir['cybermoney'])
{
print "You do not have enough banked money to withdraw this amount.";
}
else
{
$fee=ceil($_POST['withdraw']*75/1000);
if($fee > 750000) { $fee=750000; }
$gain=$_POST['withdraw']-$fee;
$ir['cybermoney']-=$gain;
$db->query("UPDATE users SET cybermoney=cybermoney-$gain, money=money+$gain where userid=$userid");
print "You ask to withdraw $gain, 

the teller hands it over after she takes the bank fees. 

[b]You now have \${$ir['cybermoney']} in the Cyber Bank.[/b]

[url='cyberbank.php']> Back[/url]";
}
}
$h->endpage();
?>

 

Pretty sure it works now

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...