Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/208962-beginners-oo-php-problems/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.