writing into the database and a php problem...
Posted: Mon Aug 29, 2005 1:49 pm
Hi, i need to know how can i write into a field in a table in my database, i forgot the full function... i only remember UPDATE...
... so if anyone knows the function it will be realy helpful... and the problem i have in php is that i need to make a form where users can withdraw/deposit money so i made script:
the $storage is a var taken from the database this var includes the amount of money the user has in his storage in the bank. the main problem is that the code doesn't detect the input of the user... if he wrote 100000000 in the withdraw input and he only has 999 money in the storage the script doesn't say he can't withdraw more then he has... 
Code: Select all
<?php
echo "$_SESSION[username] , ברוך הבא לבנק. מה תרצה לעשות?";
$result=mysql_query("SELECT * FROM RPG2");
$storage=mysql_result($result,$id,"storage");
$storage_limit=mysql_result($result,$id,"storage_limit");
echo "<table><tr><td>";
echo "<font color='white'>כסף מאוחסן: $storage <img src='cerion.gif'></font><br>";
echo "</td><td><img src='icons/chest.png'></td></tr></table>";
echo "<font color='#AAAABB'><b>מגבלת אחסון: עד $storage_limit </b><img src='cerion.gif'></font><br>";
echo "<table><tr><td>";
echo "<form method='post' action='bank.php'>";
echo "<font color='white'>משוך כסף: <input type='text' name='withdraw' value='' size='11'></font>
<br><input type='submit' name='withdraw' value='deposit' size='6'>";
echo "</td><td><img src='icons/withdraw.png'></td></tr></table>";
$sql4 = "SELECT * FROM RPG WHERE id = '$id'";
$result4 = mysql_query($sql4);
$r=mysql_fetch_array($result4);
$money=$r["money"];
echo "<table><tr><td>";
$result2=mysql_query("SELECT * FROM RPG");
// $money=mysql_result($result2,$id,"money");
$rm=mysql_fetch_array($result2);
$money=$rm['money'];
echo "<font color='white'>הפקד כסף: <input type='text' name='deposit' value='' size='11'></font>
<br><input type='submit' name='withdraw' value='withdraw' size='6'></form>";
echo "</td><td><img src='icons/deposit.png'></td></tr></table>";
--------------------------------------- !!! PROBLEM HERE !!! ---------------------------------------
if($_POST['withdraw'] > $storage) {
echo "you can not withdraw this amount of money becuase you do not have it in your storage...";
}
elseif($_POST['withdraw'] <= $storage) {
$withdraw=$_POST['withdraw'];
echo "you withdrawed $withdraw <img src='cerion.gif'>";
}
else {
echo "<div dir='rtl'>";
echo "<li>הכסף נקרא סריון, הסימן שמייצג את הכסף הוא: <img src='cerion.gif'>!";
echo "<li>אתה לא יכול למשוך יותר כסף ממה שיש לך באחסון הכסף!";
echo "<li>אתה לא יכול להפקיד כסף יותר ממגבלת האחסון!";
echo "</div>";
}
?>