Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/135334-help-please/
Share on other sites

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);

Link to comment
https://forums.phpfreaks.com/topic/135334-help-please/#findComment-704899
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/135334-help-please/#findComment-704952
Share on other sites

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); 

Link to comment
https://forums.phpfreaks.com/topic/135334-help-please/#findComment-705013
Share on other sites

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/135334-help-please/#findComment-705046
Share on other sites

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']);
}

 

 

Link to comment
https://forums.phpfreaks.com/topic/135334-help-please/#findComment-705053
Share on other sites

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.