Another question...

For discussions about game development that does not fit in any of the other topics.
Post Reply
Baseball435
Posts: 548
Joined: Sun May 30, 2010 3:49 am

Another question...

Post by Baseball435 »

I am trying to make a script so that you can store money in your house and then take it back out(i havent done that part yet) and i can get the money into the storage but i cant subtract money out of the players money for some reason. I cant figure it out. Here is the code:

Code: Select all

<?php

session_start();

include 'C:\wamp\www\php website\config\connect.php';
include 'C:\wamp\www\php website\config\session.php';

$username = $_SESSION['username'];
$id = $_SESSION['houseid'];
$housename = $_SESSION['housename'];
$housemap = $_SESSION['housemap'];
$houseowner = $_SESSION['houseowner'];
$housestorage = $_SESSION['housestorage'];

$playerinfo="SELECT * from users where username='$username'";
$playerinfo2=mysql_query($playerinfo) or die("Could not get user stats");
$playerinfo3=mysql_fetch_array($playerinfo2);

$houseinfo="SELECT * from housing where id=$id";
$houseinfo2=mysql_query($houseinfo) or die("Could not get house stats");
$houseinfo3=mysql_fetch_array($houseinfo2);

$putmoney = $_POST['addmoney'];
$playermoney = $playerinfo3['money'];
$storage = $houseinfo3['storage'];
$playerid = $_SESSION['playerid'];

if(isset($_SESSION['username'])) {
if($putmoney > $playerinfo['money']) {
	echo "<center>You Don't Have That Much Money!<br /></center>";
} elseif($putmoney <= 0) {
	echo "<center>You Can't Put In Money Less Then 0 or Equal To 0!!<br /></center>";
} elseif($putmoney = "") {
	echo "<center>Please type in the amount of money you want to store!<br /><center>";
}else {
	$playermoney = $playermoney - $putmoney;
	$storage = $storage + $putmoney;
	
	mysql_query("UPDATE users SET money='$playermoney'
	WHERE username='$username'");
	
	mysql_query("UPDATE housing SET storage='$storage'
	WHERE id=$id");
	
	echo "<center><br /><br /><br /><br />". $putmoney ." gold was added into your house storage!<br />";
}
}
?>
<html>
<LINK REL=StyleSheet HREF="style.css" TYPE="text/css" MEDIA=screen>
<head>
<title>Add Money To House<title>
</head>
<body>
<center><a href="playerhouse.php">Back To Your House</a></center>
</body>
</html>
this part:

Code: Select all

	mysql_query("UPDATE users SET money='$playermoney'
	WHERE username='$username'");
is where i think its not working. I get no errors but when i press add money it adds storage money but doesnt subtract the money added from the money the player has. So if you could help me that would be great! Thanks!

~baseball435
User avatar
kaos78414
Posts: 507
Joined: Thu Jul 22, 2010 5:36 am

Re: Another question...

Post by kaos78414 »

The only mistake I see is this:

Code: Select all

if($putmoney > $playerinfo['money']) {
should be

Code: Select all

if($putmoney > $playerinfo3['money']) {
w00t
Post Reply

Return to “General Development”