--------------------------------------------------------first issue:---------------------------------------------------------
ok its not adding the cityid to one table...here are the codes:
Code: Select all
//insert into users table
$sql2="INSERT INTO users (username, points, mycities, email, password) VALUES ('$name', '5', '1', '$email', '$password')";
$result2=mysql_query($sql2);
if ($result2)
{
//starting values
$mycityname = $name . "\'s city";
$sql43="SELECT * FROM users WHERE username='$name'";
$result10=mysql_query($sql43);
$result99=mysql_fetch_array($result10);
$userid = $result99['id'];
$sql3="INSERT INTO resources (userid, cityname, wood, stone, iron, food, people, gold, happiness, loyalty) VALUES ('$userid', '$mycityname', '200', '200', '200', '150', '10', '200', '100', '100')";
$result3=mysql_query($sql3) or die ('Error A:'. mysql_error() . ": " . mysql_error());
if ($result3)
{
$search="SELECT * from resources where userid='$userid'";
$search2=mysql_query($search) or die("could not cityid");
$search3 = mysql_fetch_array($search2);
$cityid = $search2['id'];
}
if ($search3)
{
$sql3="INSERT INTO player_buildings (cityid, userid, buildingid, buildingtype, tagid) VALUES ('$cityid', '$userid', '250', 'flag', 'tag1')";
$result3=mysql_query($sql3) or die ('Error B:'. mysql_error() . ": " . mysql_error());
}
this is how it looks in the player_buildings table:
id cityid userid buildingid buildingtype tagid
1 7 24 250 flag tag1
2 7 24 1 townhall tag2
3 7 24 21 warehouse tag3
5 0 27 250 flag tag1
(id's 1-3 i manually inserted and id 5 is what it did just after i registered a new account. so its adding everything except the cityid)
----------------------------------------------------second issue:----------------------------------------------------
this one a little hard to explain but ill try my best. ok this is the users table:
id username points mycities email password current_city
23 slav 5 1 ******** ********* 6
24 test 5 1 ******** ********* 7
25 house 5 1 ******** ********* 10
27 the 5 1 ******** ********* 0
here the problem is that its supposed to update the current_city field each time the player changes cities or when the player logs in, it goes to that current_city id #.(this is the city id) and so i registered that account with the username 'the' and it didnt change the current city. here is the coding behind this:
Code: Select all
<?php
include_once 'confff.php';
session_start();
(!isset($_SESSION['uid'])) ? header("Location: index.html") : "";
$uid = $_SESSION['uid'];
$_SESSION['uid'] = $uid;
if(isset($_POST['city_change'])){
mysql_query("UPDATE users SET current_city='$_POST[city_change]' WHERE id='$uid'");
}
?>
<?php
//current city
$sql = mysql_query("SELECT current_city FROM users WHERE id='$uid'");
$city = mysql_fetch_array($sql);
if($city['current_city'] < 1)
{
$sql = mysql_query("SELECT id FROM resources WHERE userid='$uid'");
$city2 = mysql_fetch_array($sql);
mysql_query("UPDATE users SET current_city='$city2' WHERE id='$uid'");
$cityview = $city2['id'];
}
else {
$cityview = $city['current_city'];
}
?>
<link href="maintemplate.css" rel="stylesheet" type="text/css" />
<div id="backgroundpic">
<?php
echo "<img src='/images/part1.GIF'>";
?>
</div>
<div id="townview">
<?php
echo "<img src='/images/citytiles.png'>";
?>
</div>
<form method="post">
<div id= "cities">
<?php
$sql = mysql_query("SELECT cityname FROM resources WHERE id='$cityview'");
$cityname = mysql_fetch_array($sql);
echo $cityname['cityname'];
?>
<select name="city_change">
<?php
//drop down box
$sql = mysql_query("SELECT * FROM resources WHERE userid='$uid'");
while($row = mysql_fetch_array($sql))
echo "<option value='" . $row['id'] . "'>" . $row['cityname'] . "</option>";
?>
</select>
<input type="submit" value="change city" />
</form>
</div>
