Problem med GET
HejJeg har en fil, som skal tage noget via get, og så sætte det ind en variabel, plus bruge det i en Mysql query, jeg tror problemet ligger i at jeg vil outputte GET med {}, men jeg ved ikke hva der skal sætte ind i stedet for tuborgklammerne...
Kode:
<?php
session_start();
mysql_connect("localhost", "***", "***") or die("There was an error connecting to the mysql server.");
mysql_select_db("traviannews_dk");
$username=$_SESSION['username'];
$password=$_SESSION['password'];
$result=mysql_query("SELECT * FROM brugere WHERE username='$username' AND password='$password'");
if(mysql_num_rows($result) == 0){
die("Sorry, you are no longer logged in, please login again to continue playing.");
}
else{
while($r=mysql_fetch_assoc($result)){
//This is where you would define all your resources, buildings, units, etc.
$trop1=$r['trop1'];
$sten=$r['sten'];
$trae=$r['trae'];
$metal=$r['metal'];
$korn=$r['korn'];
$stenprod=$r['stenprod'];
$traeprod=$r['traeprod'];
$kornprod=$r['kornprod'];
$metalprod=$r['metalprod'];
$psten=$r['psten'];
$ptrae=$r['ptrae'];
$pmetal=$r['pmetal'];
$pkorn=$r['pkorn'];
}
}
$sten_spent = $p{$_GET['byg']} * 1.5;
$trae_spent = $p{$_GET['byg']} * 2;
$metal_spent = $p{$_GET['byg']} * 2.5;
$korn_spent = $p{$_GET['byg']} * 1;
if($sten_spent > $sten){
echo "Sorry, this action would cost $sten_spent sten and you only have $sten sten";
}
elseif($trae_spent > $trae){
echo "Sorry, this action would cost $trae_spent and you only have $trae";
}
elseif($metal_spent > $metal){
echo "Sorry, this action would cost $metal_spent and you only have $mteal";
}
elseif($korn_spent > $korn){
echo "Sorry, this action would cost $korn_spent and you only have $korn";
}
else{
$newsten = $sten - $sten_spent;
$newtrae = $trae - $trae_spent;
$newmetal = $metal - $metal_spent;
$newkorn = $korn - $korn_spent;
$new{$_GET['byg']}prod = ${$_GET['byg']}prod + 1;
$newp{$_GET['byg']} = $p{$_GET['byg']} * 1.5;
//The above defines the new variables that will be updated shortly. They are the new values for your money, unit1 and unit2. Again, if you have more than 2 units, do the same sort of thing, but with more units.
//Now we'll run the query to update the row, and add on the new units, and take away the money
mysql_connect("localhost", "***", "***") or die("There was an error connecting to the mysql server.");
mysql_select_db("traviannews_dk");
mysql_query("UPDATE brugere SET {$_GET['byg']}prod='$new{$_GET['byg']}prod', sten='$newsten', trae='$newtrae', metal='$newmetal', korn='$newkorn', p{$_GET['byg']}='$newp{$_GET['byg']}' WHERE username='$username' AND password='$password'");
echo "Thank you, your purchases have been made, and you spend $sten_spent Sten, $trae_spent Træ, $metal_spent Metal og $korn_spent korn.";
}
?>
BTW, scriptet virker hvis jeg ikke bruger GET, men bare sætter ordet in manuelt...
På forhånd tak
//cot
