• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Database not storing stuff?

Sain Cai

Beautiful Daddy
NLC
I am having a problem with a set of php code (well several, but will display only one for now) Here is some snippets of the function and the place where the "purchase land" is, the database name where the land value is kept is called 'land':

Code:
elseif ($userrow["treasury"] >= $total) 
{ 
$land = $userrow["land"];
$newgold = $userrow["treasury"] - $total; 
$newland = $userrow["land"] + $landacres; 

$page = "<table width=100%><tr><td class=title align=center>Castle ".$userrow["landname"]."</td></tr></table><br>"; 
$page .= "<table width=100%><tr><td align=center height=400 valign=top>You bought $landacres acres of land.<br><br>"; 
$page .= "Go back and <A href='index.php?do=land'>manage</a> your land.</td></tr></table>"; 
$query = doquery("UPDATE {{table}} SET treasury='$newgold', land='$newland'  WHERE id='".$userrow["id"]."' LIMIT 1", "users"); 
} 
}

This is where the html that calls the above is:
Code:
<table width=100% cellpadding=0 cellspacing=0 border=0 align=center><tr><td align=center class=title>
<b>Territory for ".$userrow["landname"]." Castle
</b></td></tr></table>
<table width=98% cellpadding=0 cellspacing=0 border=0><tr><td align=center>
You may purchase an acre of land for 250 gold. Higher land values increases the amount of taxes you collect, and how many soldiers you can hold. You can have 10 soldiers per acre of land you own.
<br><br><center>
<form action=\"index.php?do=land\" method=\"post\"><input type=\"submit\" name=\"buyland\" value=\"purchase\" /> <input type =\"text\" name=\"landacres\" size=\"5\" /></form> acres 
</center><br><br>
</td></tr></table>

Now the prob is it takes the money out of the treasury ok, but does not add the land when called upon. Right now it displays 100 acres of land owned, but when I buy land, it still shows 100 cres, even though phpmyadmin shows a higher and proper amount.

There is a similar code for troops, and that works fine.
 
Last edited:
1. Make sure the mysql connection is working, then do this and tell me if you got any error.

Replace
Code:
$query = doquery("UPDATE {{table}} SET treasury='$newgold', land='$newland'  WHERE id='".$userrow["id"]."' LIMIT 1", "users");

with
Code:
$query = doquery("UPDATE {{table}} SET treasury='$newgold', land='$newland'  WHERE id='".$userrow["id"]."' LIMIT 1", "users") or die("#Damn query error");
 
yes, do get back to us with the error using the above code but from what i can see it is the query string.

PHP:
$query = doquery("UPDATE {{table}} SET treasury='$newgold', land='$newland'  WHERE id='".$userrow["id"]."' LIMIT 1", "users");
change to
PHP:
$query = doquery("UPDATE `TABLE_NAME` SET treasury='$newgold', land='$newland'  WHERE id='".$userrow["id"]."' LIMIT 1");


where TABLE_NAME = the table name in the database
 
1. Make sure the mysql connection is working, then do this and tell me if you got any error.

Replace
Code:
$query = doquery("UPDATE {{table}} SET treasury='$newgold', land='$newland'  WHERE id='".$userrow["id"]."' LIMIT 1", "users");

with
Code:
$query = doquery("UPDATE {{table}} SET treasury='$newgold', land='$newland'  WHERE id='".$userrow["id"]."' LIMIT 1", "users") or die("#Damn query error");


I replaced the code, and nothing happened. By this it went to the "You purchased X amount of land", just like it has, but still no update to the page, and no gold deduction. :(
 
yes, do get back to us with the error using the above code but from what i can see it is the query string.

PHP:
$query = doquery("UPDATE {{table}} SET treasury='$newgold', land='$newland'  WHERE id='".$userrow["id"]."' LIMIT 1", "users");
change to
PHP:
$query = doquery("UPDATE `TABLE_NAME` SET treasury='$newgold', land='$newland'  WHERE id='".$userrow["id"]."' LIMIT 1");


where TABLE_NAME = the table name in the database

I tried this and got a query error: Missing argument 2 for doquery(), called in /home/dragonth/public_html/kingdoms.php on line 75 and defined in /home/dragonth/public_html/lib.php on line 61

line 61 in lib.php is: function doquery($query, $table) { // Something of a tiny little database abstraction layer.

What I dont understand is how this doesnt work:
PHP:
$query = doquery("UPDATE {{table}} SET treasury='$newgold', land='$newland'  WHERE id='".$userrow["id"]."' LIMIT 1", "users"); 
}

but this does:
PHP:
$query = doquery("UPDATE {{table}} SET treasury='$newgold', offarmy='$newoff' WHERE id='".$userrow["id"]."' LIMIT 1", "users");

same thing, but a couple tables different
 
What I dont understand is how this doesnt work:
PHP:
$query = doquery("UPDATE {{table}} SET treasury='$newgold', land='$newland'  WHERE id='".$userrow["id"]."' LIMIT 1", "users"); 
}

but this does:
PHP:
$query = doquery("UPDATE {{table}} SET treasury='$newgold', offarmy='$newoff' WHERE id='".$userrow["id"]."' LIMIT 1", "users");

same thing, but a couple tables different

I now think I understand the function without seeing it. The new code will only work if you change the tables in the database as well.
 
Somehow I have things working properly. After looking through the mod installation, I removed one piece of code, and it works fine. I then repalced in the exact area, and still works fine (for now lol)

I am having probs with another area (well several. I cant get ahold of the people who created the mods). This deals with if/else cases:

PHP:
if (isset($_POST["attack"])) 
{ 

$thetime = date("U"); 
$timelimit = $thetime - 100 * 1; 

$victimid = $_POST['victimid']; 
$victimid = strip_tags($victimid); 

$victimselect = "SELECT * from dk_users where id='$victimid'"; 
$victimselect2 = mysql_query($victimselect) or die ("Could not select Victim"); 
$victimselect3 = mysql_fetch_array($victimselect2); 

$minlim = 2 * $victimselect3["land"]; 

$attacklimit = "SELECT COUNT(*) as attname from dk_battlerecords where id='$vicitimselect3[id]'"; 
$attacklimit2 = mysql_query($attacklimit) or die ("Could not get limit"); 
$attacklimit3 = mysql_result($attacklimit2,0); 

if ($userrow["land"] > $minlim) 
{ 
$page = "<table width=100%><tr><td class=title align=center>War Room</td></tr></table><br>";
$page .= "<div align=center>You cannot attack someone with less than half your land.<br><br>";
$page .= "Go back to <a href=\"index.php?do=land\">manage</a> your land.</div>"; 
} 

elseif ($userrow["attackaction"] > $timelimit) 
{ 

$thetime <= $userrow["timelimit"]; 

$page = "<table width=100%><tr><td class=title align=center>War Room</td></tr></table><br>";
$page .= "<div align=center>You have attacked within the last hour.<br><br>";
$page .= "You can only take one of these actions in each 1-hour period.<br /><br />";
$page .= "Go back to <a href=\"index.php?do=land\">manage</a> your land.</div>"; 
} 

elseif ($userrow["id"] == $victimselect3["id"]) 
{ 
$page = "<table width=100%><tr><td class=title align=center>War Room</td></tr></table><br>";
$page .= "<div align=center>You may not attack yourself.<br><br>";
$page .= "Go back to <a href=\"index.php?do=land\">manage</a> your land.</div>"; 
} 

elseif ($attacklimit3 >= 2) 
{ 
$page = "<table width=100%><tr><td class=title align=center>War Room</td></tr></table><br>";
$page .= "<div align=center>That person has already been attacked 5 times since there last login.<br><br>";
$page .= "You may not attack them.<br><br>Go back to <a href=\"index.php?do=land\">manage</a> your land.</div>"; 
} 

elseif ($victimselect3["land"] <= 0) 
{ 
$page = "<table width=100%><tr><td class=title align=center>War Room</td></tr></table><br>";
$page .= "<div align=center>You cannot attack someone that has no land.<br><br>";
$page .= "Go back to <a href=\"index.php?do=land\">manage</a> your land.</div>"; 
} 

elseif ($userrow["land"] < 1) 
{ 
$page = "<table width=100%><tr><td class=title align=center>War Room</td></tr></table><br>";
$page .= "<div align=center>You can not attack someone if you have no land to attack from.<br><br>";
$page .= "Go back to <a href=\"index.php?do=land\">manage</a> your land.</div>"; 
} 

$query = doquery("UPDATE {{table}} SET attackaction='$thetime' WHERE id='".$userrow["id"]."' LIMIT 1", "users");


None of these commands work. I input 1 for the id to attack, which is myself, and I lose the battle and take x amount of troops. I set the limit to protect people to 1 so they can only be attacked once, but I can attack several times. User 2 has 0 land, so he shouldnt be able to be attacked but can, etc.
 
Back
Top