HI,
I have a problam with my script, it checks the user's details from a file, the bank script i have made is slightly not working,
When a user deposites 25 into the bank, and then withdraws 100, (this is starting with 0)
it puts the bank account to -75, how can i make it so it won't withdraw if there is not enough?
Here is the script i use:
<?php
} else {
$userlist = file("users.inc.php");
$done = false;
$auth = false;
$found = false;
$i = 0;
while ((!$found) && ($i<count($userlist))) {
$i++;
list($n,$p,$a,$e,$g,$s,$m,$a1) = explode(':',$userlist[$i]);
$found = ($n==$user);
echo "<br>Please Wait...";
} if ($com == 2 && $m <= $price) { die("<br>Error: You don't have enough money<br>"); }
elseif ($com == 1 && $a1 <= $price) { die("<br>Error: You don't have enough money in your account<br>"); }
elseif (!$com) { die("<br>Error: You must select either Deposit or withdraw<br>"); }
elseif ($com == 2 && $m >= $price) {
$m -= $price;
$a1 += $price;
$m = ($m < $price) ? $m : $m;
$a1 = ($m < $price) ? $a1 : $a1;
$userlist[$i] = implode(':',array($n,$p,$a,$e,$g,$s,$m,$a1));
$fd = fopen("users.inc.php","w");
fputs($fd,"<?php die(\"Access restricted\"); ?>\n");
for ($i=1; $i<count($userlist); $i++) {
fputs($fd,chop($userlist[$i])."\n");
}
fclose($fd);
echo "<script>window.opener.document.location.reload(); window.close();</script>";
}
elseif ($com == 1 && $a1 >= $price) {
$m += $price;
$a1 -= $price;
$m = ($m < $price) ? $m : $m;
$a1 = ($a1 < $price) ? $a1 : $a1;
$userlist[$i] = implode(':',array($n,$p,$a,$e,$g,$s,$m,$a1));
$fd = fopen("users.inc.php","w");
fputs($fd,"<?php die(\"Access restricted\"); ?>\n");
for ($i=1; $i<count($userlist); $i++) {
fputs($fd,chop($userlist[$i])."\n");
}
fclose($fd);
echo "<script>window.opener.document.location.reload(); window.close();</script>";
}
}
?>
The form has radio butons to choose $com, $com as 1 is withdraw and 2 is deposit, $m is the users money and $a1 is the bank account.
thanxs to all the help,