Scex Posted December 3, 2008 Share Posted December 3, 2008 Hi, im currently learning and progressing in php by making a basic mmorpg for learning purposes only.. but im having trouble with a little section of it, i want "users" to be able to buy villages and for it then to update the km_villages db table aswell as the km_users table. I would do it all in km_users but i want them to be able to buy multiple villages each with different levels of buildings and troop counts etc. Much like Tribal Wars if anyones played it. Anyway hers what i have so far. <html> <table> <body> <tr> <td colspan=2> <h2 align="center">TEST</h2> </td> </tr> <tr> <td > <h4 align="center">Ram image</h4> </td> <td> <form action="buyvil.php" method="post"> <br>Buy villages: <INPUT TYPE="text" name="vil"></p> <input type="submit" value="Buy"> </form> </td> </tr> </table> </body> </html> Basic page so i could go through with it, heres buyvil.php <?php include 'connect.php'; session_start(); ?> <br><br> <link rel="stylesheet" href="style.css" type="text/css"> <?php if (isset($_SESSION['player'])) { $player=$_SESSION['player']; $userstats="SELECT * from km_users where playername='$player'"; $userstats2=mysql_query($userstats) or die("Could not get user stats"); $userstats3=mysql_fetch_array($userstats2); $vils="SELECT * from km_villages where playername='$player'"; $vils2=mysql_query($vils) or die("Could not get user stats"); $vils3=mysql_fetch_array($vils2); if(isset($_POST['submit'])) { $vil=$_POST['vil']; $vil=strip_tags($vil); $vilcost=2000; $totalcost=$vil*$vilcost; $max=10; $threshold=date("U")-60*1; $thetime=date("U"); print "<center>"; print "<table class='maintable'>"; print "<tr class='headline'><td><center>Tarenza Warrior Grounds</center></td></tr>"; print "<tr class='mainrow'><td>"; if($vil<0) { die("You cannot buy negative villages"); } else if($totalcost>$userstats3[gold]) { die("You do not have that much gold, go back to <A href='index.php'>Main page</a>"); } else if($vils3[iD]>$max) { die("You cannot have more than $max villages, go back to <A href='index.php'>Main</a>"); } else if($userstats3[lastaction]>$threshold) { die("You have to wait 1 minute after an attack to buy troops, go back to <A href='index.php'>Main</a>."); } else if($vil<=10) { $getarmy="update km_villages set user='$player', type='village', pts=pts+'10', timber=timber+'30', iron=iron+'30', coal=coal+'30' where ID='$vils3[iD]'"; mysql_query($getarmy) or die("Can't get Warriors"); $getarmys="update km_users set gold=gold-'$totalcost' where ID='$userstats3[iD]'"; mysql_query($getarmys) or die("Can't get Warriors"); print "$warr Warriors purchased. Go back to <A href='buyarmy.php'>Recruitment</a>."; } print "</td></tr></table>"; } } else { print "Sorry, not logged in please <A href='login.php'>Login</a><br>"; } ?> and heres the table dump $installusers="CREATE TABLE km_villages ( ID bigint(21) NOT NULL auto_increment, user varchar(15) NOT NULL default '', type varchar(15) NOT NULL default 'camp', pts bigint(21) NOT NULL default '0', timber int(10) NOT NULL default '70', iron int(10) NOT NULL default '70', coal int(10) NOT NULL default '70', academy int(10) NOT NULL default '0', intel int(10) NOT NULL default '0', fort int(10) NOT NULL default '0', bg int(10) NOT NULL default '0', hq int(10) NOT NULL default '0', arena int(10) NOT NULL default '0', thall int(10) NOT NULL default '0', tmill int(10) NOT NULL default '0', imill int(10) NOT NULL default '0', cmill int(10) NOT NULL default '0', warrior bigint(20) NOT NULL default '0', ram bigint(20) NOT NULL default '0', beserker bigint(20) NOT NULL default '0', champion bigint(20) NOT NULL default '0', scout bigint(20) NOT NULL default '0', trojan bigint(20) NOT NULL default '0', virus bigint(20) NOT NULL default '0', archer bigint(20) NOT NULL default '0', warlock bigint(20) NOT NULL default '0', paladin bigint(20) NOT NULL default '0', science bigint(20) NOT NULL default '0', PRIMARY KEY (ID) )"; mysql_query($installusers) or die("Could not install users"); Anyone got ideas? Quote Link to comment Share on other sites More sharing options...
Scex Posted December 3, 2008 Author Share Posted December 3, 2008 I changed $vils="SELECT * from km_villages where playername='$player'"; $vils2=mysql_query($vils) or die("Could not get user stats"); $vils3=mysql_fetch_array($vils2); to $vils="SELECT * from km_villages where user='$player'"; $vils2=mysql_query($vils) or die("Could not get user stats"); $vils3=mysql_fetch_array($vils2); Quote Link to comment Share on other sites More sharing options...
daveoffy Posted December 3, 2008 Share Posted December 3, 2008 Does it work now with that changed code? Quote Link to comment Share on other sites More sharing options...
Scex Posted December 3, 2008 Author Share Posted December 3, 2008 Nope! Quote Link to comment Share on other sites More sharing options...
peranha Posted December 3, 2008 Share Posted December 3, 2008 what exactly is it doing/not doing and is supposed to?? Quote Link to comment Share on other sites More sharing options...
Scex Posted December 3, 2008 Author Share Posted December 3, 2008 I am trying to get the user (me) to buy a village and it update my users info to store a village, but i want to be able to buy multiple villages each with different statistics/ amount of troops etc. So i figured id need a new table for this so Km_villages came along. When i click buy, it goes to buyvil and shows a blank page. Quote Link to comment Share on other sites More sharing options...
peranha Posted December 3, 2008 Share Posted December 3, 2008 At the very top of the page put error_reporting(E_ALL); and after all the queries add mysql_error() I fixed the one query below for you. $vils="SELECT * from km_villages where user='$player'"; $vils2=mysql_query($vils) or die("Could not get user stats".mysql_error()); $vils3=mysql_fetch_array($vils2); Quote Link to comment Share on other sites More sharing options...
Scex Posted December 3, 2008 Author Share Posted December 3, 2008 Notice: Undefined variable: QUERY_STRING in /home/a6382197/public_html/connect.php on line 2 <?php parse_str("$QUERY_STRING"); $db = mysql_connect("00000", "00000", "00000") or die("Could not connect."); if(!$db) die("no db"); if(!mysql_select_db("0000",$db)) die("No database selected."); if(!get_magic_quotes_gpc()) { $_GET = array_map('mysql_real_escape_string', $_GET); $_POST = array_map('mysql_real_escape_string', $_POST); $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE); } else { $_GET = array_map('stripslashes', $_GET); $_POST = array_map('stripslashes', $_POST); $_COOKIE = array_map('stripslashes', $_COOKIE); $_GET = array_map('mysql_real_escape_string', $_GET); $_POST = array_map('mysql_real_escape_string', $_POST); $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE); } ?> That has not ever caused problems with my other forms etc.. so i doubt its that. Quote Link to comment Share on other sites More sharing options...
premiso Posted December 3, 2008 Share Posted December 3, 2008 Replace parse_str("$QUERY_STRING"); with if (isset($QUERY_STRING)) { parse_str($QUERY_STRING); } But I think $QUERY_STRING assumes register_globals is on, it is better to code it this way: if (isset($_SERVER['QUERY_STRING'])) { parse_str($_SERVER['QUERY_STRING']); } Quote Link to comment Share on other sites More sharing options...
Scex Posted December 3, 2008 Author Share Posted December 3, 2008 OK but this wouldnt be causing me problems in the coding above would it Quote Link to comment 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.