Jouninshinobi
03-30-2005, 08:21 PM
I have no clue why my code won't work. I've tried echo and it all seemed right
This is what it echoed
UPDATE lands SET Apartment='1'+'13' WHERE Apartment='Apartment'and name='jounin'
It worked fine when I plugged it in but for some reason the actual program didn't work. While trying to figure it out I came across something about Primary key constraints in a table giving problems to the [update] command. It said to use the [ignore] command but when i tried it, it failed. If primary key constraints really does cause error is there some way around it?
For further refrence heres my code
<?php
//killmonster amin index
include 'connect.php';
session_start();
$userstats="SELECT * from km_users WHERE playername='$player'";
$userstats2=mysql_query($userstats) or die("Could not get user stats");
$userstats3=mysql_fetch_array($userstats2);
$sel="SELECT * from colors WHERE type='$userstats3[area]'";
$sel2=mysql_query($sel) or die("Could not get user stats");
$sel3=mysql_fetch_array($sel2);
print "<link rel='stylesheet' href='$sel3[code].css' type='text/css'>";
print "<body bgcolor='#000033' text='#FFFFFF' link='$sel3[links]' vlink='$sel3[links]' alink='$sel3[links]'>";
?>
<?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);
if(isSET($_POST['submit']))
{
print "<center>";
print "<table class='maintable'>";
print "<tr class='headline'><td><center>Buy LAND</center></td></tr>";
print "<tr class='mainrow'><td>";
$amount=$_POST['amount'];
$type=$_POST['type'];
$amount=strip_tags($amount);
$amt="select * from lands WHERE name='$player'";
$amt1=mysql_query($amt);
$amt2=mysql_fetch_array($amt1);
$total=$amount*$lAND[price];
if($lANDacres<0)
{
print "You cannot buy negative Houses. <A href='lAND.php'>Go back to main</a>.";
}
else if($userstats3[gold]<$total)
{
print "You do not have enough cash to buy that many Houses. <A href='lAND.php'>Go back to main</a>.";
}
else if($userstats3[gold]>=$total)
{
$getlAND="UPDATE km_users SET gold=gold-'$total' WHERE ID='$userstats3[ID]'";
echo "$gethouse";
echo "<br>$amt2[type]";
mysql_query($getlAND) or die("Could not buy lAND");
$gethouse1="UPDATE lands SET Hut='$amt2[Hut]'+'$amount' WHERE Hut='$type'and name='$player'";
$gethouse2="UPDATE lands SET TreeFort='$amt2[TreeFort]'+'$amount' WHERE TreeFort='$type'and name='$player'";
$gethouse3="UPDATE lands SET Palace='$amt2[Palace]'+'$amount' WHERE Palace='$type'and name='$player'";
$gethouse4="UPDATE lands SET Igloo='$amt2[Igloo]'+'$amount' WHERE Igloo='$type'and name='$player'";
$gethouse5="UPDATE lands SET FrozenTower='$amt2[FrozenTower]'+'$amount' WHERE FrozenTower='$type'and name='$player'";
$gethouse6="UPDATE lands SET IceFortress='$amt2[IceFortress]'+'$amount' WHERE IceFortress='$type'and name='$player'";
$gethouse7="UPDATE lands SET BeachHouse='$amt2[BeachHouse]'+'$amount' WHERE BeachHouse='$type'and name='$player'";
$gethouse8="UPDATE lands SET Lighthouse='$amt2[Lighthouse]'+'$amount' WHERE Lighthouse='$type'and name='$player'";
$gethouse9="UPDATE lands SET FloatingFortress='$amt2[FloatingFortress]'+'$amount' WHERE FloatingFortress='$type'and name='$player'";
$gethouse10="UPDATE lands SET StormShelter='$amt2[StormShelter]'+'$amount' WHERE StormShelter='$type'and name='$player'";
$gethouse11="UPDATE lands SET Factory='$amt2[Factory]'+'$amount' WHERE Factory='$type'and name='$player'";
$gethouse12="UPDATE lands SET PowerPlant='$amt2[PowerPlant]'+'$amount' WHERE PowerPlant='$type'and name='$player'";
$gethouse13="UPDATE lands SET Crater='$amt2[Crater]'+'$amount' WHERE Crater='$type'and name='$player'";
$gethouse14="UPDATE lands SET MagmaWall='$amt2[MagmaWall]'+'$amount' WHERE MagmaWall='$type'and name='$player'";
$gethouse15="UPDATE lands SET IgneousCastle='$amt2[IgneousCastle]'+'$amount' WHERE IgneousCastle='$type'and name='$player'";
$gethouse16="UPDATE lands SET Shelter='$amt2[Shelter]'+'$amount' WHERE Shelter='$type'and name='$player'";
$gethouse17="UPDATE lands SET Shack='$amt2[Shack]'+'$amount' WHERE Shack='$type'and name='$player'";
$gethouse18="UPDATE lands SET AirFortress='$amt2[AirFortress]'+'$amount' WHERE AirFortress='$type'and name='$player'";
$gethouse19="UPDATE lands SET Apartment='$amt2[Apartment]'+'$amount' WHERE Apartment='$type'and name='$player'";
$gethouse20="UPDATE lands SET RowHome='$amt2[RowHome]'+'$amount' WHERE RowHome='$type'and name='$player'";
$gethouse21="UPDATE lands SET Mansion='$amt2[Mansion]'+'$amount' WHERE Mansion='$type'and name='$player'";
$gethouse22="UPDATE lands SET Barracks='$amt2[Barracks]'+'$amount' WHERE Barracks='$type'and name='$player'";
$gethouse23="UPDATE lands SET Tower='$amt2[Tower]'+'$amount' WHERE Tower='$type'and name='$player'";
$gethouse24="UPDATE lands SET Castle='$amt2[Castle]'+'$amount' WHERE Castle='$type'and name='$player'";
$gethouse25="UPDATE lands SET Chapel='$amt2[Chapel]'+'$amount' WHERE Chapel='$type'and name='$player'";
$gethouse26="UPDATE lands SET Church='$amt2[Church]'+'$amount' WHERE Church='$type'and name='$player'";
$gethouse27="UPDATE lands SET Temple='$amt2[Temple]'+'$amount' WHERE Temple='$type'and name='$player'";
$gethouse28="UPDATE lands SET BoneHut='$amt2[BoneHut]'+'$amount' WHERE BoneHut='$type'and name='$player'";
$gethouse29="UPDATE lands SET DarkTower='$amt2[DarkTower]'+'$amount' WHERE DarkTower='$type'and name='$player'";
$gethouse30="UPDATE lands SET BlackFortress='$amt2[BlackFortress]'+'$amount' WHERE BlackFortress='$type'and name='$player'";
$gethouse31="UPDATE lands SET SANDHut='$amt2[SANDHut]'+'$amount' WHERE SANDHut='$type'and name='$player'";
$gethouse32="UPDATE lands SET HollowDune='$amt2[HollowDune]'+'$amount' WHERE HollowDune='$type'and name='$player'";
$gethouse33="UPDATE lands SET Pyramid='$amt2[Pyramid]'+'$amount' WHERE Pyramid='$type'and name='$player'";
$gethouse34="UPDATE lands SET Cave='$amt2[Cave]'+'$amount' WHERE Cave='$type'and name='$player'";
$gethouse35="UPDATE lands SET Tunnel='$amt2[Tunnel]'+'$amount' WHERE Tunnel='$type'and name='$player'";
$gethouse36="UPDATE lands SET Fortress='$amt2[Fortress]'+'$amount' WHERE Fortress='$type'and name='$player'";
echo "$gethouse1<br>";
echo "$gethouse2<br>";
echo "$gethouse19<br>";
mysql_query($gethouse1) or die("Could not buy lAND1");
mysql_query($gethouse2) or die("Could not buy lAND2");
mysql_query($gethouse3) or die("Could not buy lAND3");
mysql_query($gethouse4) or die("Could not buy lAND4");
mysql_query($gethouse5) or die("Could not buy lAND5");
mysql_query($gethouse6) or die("Could not buy lAND6");
mysql_query($gethouse7) or die("Could not buy lAND7");
mysql_query($gethouse8) or die("Could not buy lAND8");
mysql_query($gethouse9) or die("Could not buy lAND9");
mysql_query($gethouse10) or die("Could not buy lAND10");
mysql_query($gethouse11) or die("Could not buy lAND11");
mysql_query($gethouse12) or die("Could not buy lAND12");
mysql_query($gethouse13) or die("Could not buy lAND13");
mysql_query($gethouse14) or die("Could not buy lAND14");
mysql_query($gethouse15) or die("Could not buy lAND15");
mysql_query($gethouse16) or die("Could not buy lAND16");
mysql_query($gethouse17) or die("Could not buy lAND17");
mysql_query($gethouse18) or die("Could not buy lAND18");
mysql_query($gethouse19) or die("Could not buy lAND19");
mysql_query($gethouse20) or die("Could not buy lAND20");
mysql_query($gethouse21) or die("Could not buy lAND21");
mysql_query($gethouse22) or die("Could not buy lAND22");
mysql_query($gethouse23) or die("Could not buy lAND23");
mysql_query($gethouse24) or die("Could not buy lAND24");
mysql_query($gethouse25) or die("Could not buy lAND25");
mysql_query($gethouse26) or die("Could not buy lAND26");
mysql_query($gethouse27) or die("Could not buy lAND27");
mysql_query($gethouse28) or die("Could not buy lAND28");
mysql_query($gethouse29) or die("Could not buy lAND29");
mysql_query($gethouse30) or die("Could not buy lAND30");
mysql_query($gethouse31) or die("Could not buy lAND31");
mysql_query($gethouse32) or die("Could not buy lAND32");
mysql_query($gethouse33) or die("Could not buy lAND33");
mysql_query($gethouse34) or die("Could not buy lAND34");
mysql_query($gethouse35) or die("Could not buy lAND35");
mysql_query($gethouse36) or die("Could not buy lAND36");
echo "<br>You bought $amount of $type. <A href='lAND.php'>Go back to main</a>.";
}
print "</td></tr></table>";
}
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
}
?>
thx alot,
This is what it echoed
UPDATE lands SET Apartment='1'+'13' WHERE Apartment='Apartment'and name='jounin'
It worked fine when I plugged it in but for some reason the actual program didn't work. While trying to figure it out I came across something about Primary key constraints in a table giving problems to the [update] command. It said to use the [ignore] command but when i tried it, it failed. If primary key constraints really does cause error is there some way around it?
For further refrence heres my code
<?php
//killmonster amin index
include 'connect.php';
session_start();
$userstats="SELECT * from km_users WHERE playername='$player'";
$userstats2=mysql_query($userstats) or die("Could not get user stats");
$userstats3=mysql_fetch_array($userstats2);
$sel="SELECT * from colors WHERE type='$userstats3[area]'";
$sel2=mysql_query($sel) or die("Could not get user stats");
$sel3=mysql_fetch_array($sel2);
print "<link rel='stylesheet' href='$sel3[code].css' type='text/css'>";
print "<body bgcolor='#000033' text='#FFFFFF' link='$sel3[links]' vlink='$sel3[links]' alink='$sel3[links]'>";
?>
<?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);
if(isSET($_POST['submit']))
{
print "<center>";
print "<table class='maintable'>";
print "<tr class='headline'><td><center>Buy LAND</center></td></tr>";
print "<tr class='mainrow'><td>";
$amount=$_POST['amount'];
$type=$_POST['type'];
$amount=strip_tags($amount);
$amt="select * from lands WHERE name='$player'";
$amt1=mysql_query($amt);
$amt2=mysql_fetch_array($amt1);
$total=$amount*$lAND[price];
if($lANDacres<0)
{
print "You cannot buy negative Houses. <A href='lAND.php'>Go back to main</a>.";
}
else if($userstats3[gold]<$total)
{
print "You do not have enough cash to buy that many Houses. <A href='lAND.php'>Go back to main</a>.";
}
else if($userstats3[gold]>=$total)
{
$getlAND="UPDATE km_users SET gold=gold-'$total' WHERE ID='$userstats3[ID]'";
echo "$gethouse";
echo "<br>$amt2[type]";
mysql_query($getlAND) or die("Could not buy lAND");
$gethouse1="UPDATE lands SET Hut='$amt2[Hut]'+'$amount' WHERE Hut='$type'and name='$player'";
$gethouse2="UPDATE lands SET TreeFort='$amt2[TreeFort]'+'$amount' WHERE TreeFort='$type'and name='$player'";
$gethouse3="UPDATE lands SET Palace='$amt2[Palace]'+'$amount' WHERE Palace='$type'and name='$player'";
$gethouse4="UPDATE lands SET Igloo='$amt2[Igloo]'+'$amount' WHERE Igloo='$type'and name='$player'";
$gethouse5="UPDATE lands SET FrozenTower='$amt2[FrozenTower]'+'$amount' WHERE FrozenTower='$type'and name='$player'";
$gethouse6="UPDATE lands SET IceFortress='$amt2[IceFortress]'+'$amount' WHERE IceFortress='$type'and name='$player'";
$gethouse7="UPDATE lands SET BeachHouse='$amt2[BeachHouse]'+'$amount' WHERE BeachHouse='$type'and name='$player'";
$gethouse8="UPDATE lands SET Lighthouse='$amt2[Lighthouse]'+'$amount' WHERE Lighthouse='$type'and name='$player'";
$gethouse9="UPDATE lands SET FloatingFortress='$amt2[FloatingFortress]'+'$amount' WHERE FloatingFortress='$type'and name='$player'";
$gethouse10="UPDATE lands SET StormShelter='$amt2[StormShelter]'+'$amount' WHERE StormShelter='$type'and name='$player'";
$gethouse11="UPDATE lands SET Factory='$amt2[Factory]'+'$amount' WHERE Factory='$type'and name='$player'";
$gethouse12="UPDATE lands SET PowerPlant='$amt2[PowerPlant]'+'$amount' WHERE PowerPlant='$type'and name='$player'";
$gethouse13="UPDATE lands SET Crater='$amt2[Crater]'+'$amount' WHERE Crater='$type'and name='$player'";
$gethouse14="UPDATE lands SET MagmaWall='$amt2[MagmaWall]'+'$amount' WHERE MagmaWall='$type'and name='$player'";
$gethouse15="UPDATE lands SET IgneousCastle='$amt2[IgneousCastle]'+'$amount' WHERE IgneousCastle='$type'and name='$player'";
$gethouse16="UPDATE lands SET Shelter='$amt2[Shelter]'+'$amount' WHERE Shelter='$type'and name='$player'";
$gethouse17="UPDATE lands SET Shack='$amt2[Shack]'+'$amount' WHERE Shack='$type'and name='$player'";
$gethouse18="UPDATE lands SET AirFortress='$amt2[AirFortress]'+'$amount' WHERE AirFortress='$type'and name='$player'";
$gethouse19="UPDATE lands SET Apartment='$amt2[Apartment]'+'$amount' WHERE Apartment='$type'and name='$player'";
$gethouse20="UPDATE lands SET RowHome='$amt2[RowHome]'+'$amount' WHERE RowHome='$type'and name='$player'";
$gethouse21="UPDATE lands SET Mansion='$amt2[Mansion]'+'$amount' WHERE Mansion='$type'and name='$player'";
$gethouse22="UPDATE lands SET Barracks='$amt2[Barracks]'+'$amount' WHERE Barracks='$type'and name='$player'";
$gethouse23="UPDATE lands SET Tower='$amt2[Tower]'+'$amount' WHERE Tower='$type'and name='$player'";
$gethouse24="UPDATE lands SET Castle='$amt2[Castle]'+'$amount' WHERE Castle='$type'and name='$player'";
$gethouse25="UPDATE lands SET Chapel='$amt2[Chapel]'+'$amount' WHERE Chapel='$type'and name='$player'";
$gethouse26="UPDATE lands SET Church='$amt2[Church]'+'$amount' WHERE Church='$type'and name='$player'";
$gethouse27="UPDATE lands SET Temple='$amt2[Temple]'+'$amount' WHERE Temple='$type'and name='$player'";
$gethouse28="UPDATE lands SET BoneHut='$amt2[BoneHut]'+'$amount' WHERE BoneHut='$type'and name='$player'";
$gethouse29="UPDATE lands SET DarkTower='$amt2[DarkTower]'+'$amount' WHERE DarkTower='$type'and name='$player'";
$gethouse30="UPDATE lands SET BlackFortress='$amt2[BlackFortress]'+'$amount' WHERE BlackFortress='$type'and name='$player'";
$gethouse31="UPDATE lands SET SANDHut='$amt2[SANDHut]'+'$amount' WHERE SANDHut='$type'and name='$player'";
$gethouse32="UPDATE lands SET HollowDune='$amt2[HollowDune]'+'$amount' WHERE HollowDune='$type'and name='$player'";
$gethouse33="UPDATE lands SET Pyramid='$amt2[Pyramid]'+'$amount' WHERE Pyramid='$type'and name='$player'";
$gethouse34="UPDATE lands SET Cave='$amt2[Cave]'+'$amount' WHERE Cave='$type'and name='$player'";
$gethouse35="UPDATE lands SET Tunnel='$amt2[Tunnel]'+'$amount' WHERE Tunnel='$type'and name='$player'";
$gethouse36="UPDATE lands SET Fortress='$amt2[Fortress]'+'$amount' WHERE Fortress='$type'and name='$player'";
echo "$gethouse1<br>";
echo "$gethouse2<br>";
echo "$gethouse19<br>";
mysql_query($gethouse1) or die("Could not buy lAND1");
mysql_query($gethouse2) or die("Could not buy lAND2");
mysql_query($gethouse3) or die("Could not buy lAND3");
mysql_query($gethouse4) or die("Could not buy lAND4");
mysql_query($gethouse5) or die("Could not buy lAND5");
mysql_query($gethouse6) or die("Could not buy lAND6");
mysql_query($gethouse7) or die("Could not buy lAND7");
mysql_query($gethouse8) or die("Could not buy lAND8");
mysql_query($gethouse9) or die("Could not buy lAND9");
mysql_query($gethouse10) or die("Could not buy lAND10");
mysql_query($gethouse11) or die("Could not buy lAND11");
mysql_query($gethouse12) or die("Could not buy lAND12");
mysql_query($gethouse13) or die("Could not buy lAND13");
mysql_query($gethouse14) or die("Could not buy lAND14");
mysql_query($gethouse15) or die("Could not buy lAND15");
mysql_query($gethouse16) or die("Could not buy lAND16");
mysql_query($gethouse17) or die("Could not buy lAND17");
mysql_query($gethouse18) or die("Could not buy lAND18");
mysql_query($gethouse19) or die("Could not buy lAND19");
mysql_query($gethouse20) or die("Could not buy lAND20");
mysql_query($gethouse21) or die("Could not buy lAND21");
mysql_query($gethouse22) or die("Could not buy lAND22");
mysql_query($gethouse23) or die("Could not buy lAND23");
mysql_query($gethouse24) or die("Could not buy lAND24");
mysql_query($gethouse25) or die("Could not buy lAND25");
mysql_query($gethouse26) or die("Could not buy lAND26");
mysql_query($gethouse27) or die("Could not buy lAND27");
mysql_query($gethouse28) or die("Could not buy lAND28");
mysql_query($gethouse29) or die("Could not buy lAND29");
mysql_query($gethouse30) or die("Could not buy lAND30");
mysql_query($gethouse31) or die("Could not buy lAND31");
mysql_query($gethouse32) or die("Could not buy lAND32");
mysql_query($gethouse33) or die("Could not buy lAND33");
mysql_query($gethouse34) or die("Could not buy lAND34");
mysql_query($gethouse35) or die("Could not buy lAND35");
mysql_query($gethouse36) or die("Could not buy lAND36");
echo "<br>You bought $amount of $type. <A href='lAND.php'>Go back to main</a>.";
}
print "</td></tr></table>";
}
}
else
{
print "Sorry, not logged in please <A href='login.php'>Login</a><br>";
}
?>
thx alot,
