Kryllster Posted July 26, 2010 Share Posted July 26, 2010 I think I understand the basic principles behind oop but Im having problem implementing code. I have a php script called deposit.php and I was wondering if someone could convert it to object code so I can see how it would be done. <?php session_start(); $username = $_SESSION['username']; // Define Form Variables $dep_gold = 0 + $_POST['dep_gold']; $dep_diamond = 0 + $_POST['dep_diamond']; $dep_rubie = 0 + $_POST['dep_rubie']; // Connect to Database include ('includes/db_config.php'); $sql="SELECT * FROM $tbl_name WHERE username='$username'"; $result=mysql_query($sql); // Put info into array while($row=mysql_fetch_assoc($result)) { // Assign Array include('includes/player_config.php'); // Test the money if($dep_gold > $onhand || $dep_diamond > $diamond || $dep_rubie > $rubie){ header("Location: mainview.php?show=warnmoney"); exit(); } else{ // update database $sql="UPDATE $tbl_name SET bank = bank + $dep_gold , onhand = onhand - $dep_gold , dbalance = dbalance + $dep_diamond , diamond = diamond - $dep_diamond , rbalance = rbalance + $dep_rubie , rubie = rubie - $dep_rubie WHERE username='$username'"; mysql_query($sql) or die (mysql_error()."<p>$sql</p>"); //echo "<META HTTP-EQUIV=\"Refresh\"CONTENT=\"0; URL=mainview.php?show=account\">"; header("Location: mainview.php?show=account"); } } ?> Is this even necessary with this code as its used in a banking system I am using in my game. I also have a withdrawal script. would it be easier to combine these to scripts. I am confused and need some direction. Thank You! Quote Link to comment https://forums.phpfreaks.com/topic/208962-beginners-oo-php-problems/ Share on other sites More sharing options...
sKunKbad Posted July 26, 2010 Share Posted July 26, 2010 Using OOP doesn't mean you can't do things procedurally. If there is a simple script like this one, you would just be complicating things by trying to make a class, creating an object, etc. If you want to learn OOP fast, you might take a look at one of the popular PHP frameworks, like CodeIgniter, and see how things are done there. CodeIgniter still allows for PHP4, so you might look at Kohana if you want something that is strictly PHP5. I'm not saying you have to use the framework, only that it shows a great example of common tasks done with OOP PHP. Quote Link to comment https://forums.phpfreaks.com/topic/208962-beginners-oo-php-problems/#findComment-1091472 Share on other sites More sharing options...
Kryllster Posted July 26, 2010 Author Share Posted July 26, 2010 Thank You very much for your reply I did learn something. I can still do things proceduraly as well which I thought everything had to have a class, constuct etc etc.. Quote Link to comment https://forums.phpfreaks.com/topic/208962-beginners-oo-php-problems/#findComment-1091483 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.