Jump to content

Beginners OO Php problems!


Kryllster

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.

Archived

This topic is now archived and is closed to further replies.

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