ユーザー名マニュアルを管理者に設定しただけでスクリプトが機能しましたが、ユーザー名を「.$_SESSION['Username'].」に設定する必要があり、コードに問題が発生します。
さまざまな方法で設定しようとしましたが、さらに問題があるのか 、それともユーザー名だけが機能していないのかわかりません。
私のコードは次のとおりです。
<?php
include "connect.php";
include "head.php";
?>
<?php
$action = $_GET['action'];
if($action == "fight"){
$checkfight = @mysql_fetch_array(@mysql_query("SELECT * FROM fights WHERE User=".$_SESSION['Username']."")); //Check if fight exist
$monstername = $checkfight['monstername'];
$monsterlevel = $checkfight['monsterlevel'];
$monsterdice = $checkfight['monsterdice'];
$monsterhp = $checkfight['monsterhp'];
$monstermana = $checkfight['monstermana'];
$monsterarmor = $checkfight['monsterarmor'];
$monstermindmg = $checkfight['monstermindmg'];
$monstermaxdmg = $checkfight['monstermaxdmg'];
if($checkfight['User'] == 'Admin') {
$selectuser = @mysql_fetch_array(@mysql_query("SELECT * FROM members WHERE Username=".$_SESSION['Username']."")); //loading the user
$currently = $selectuser['Quest'];
$userhp = $selectuser['Life'];
$usermana = $selectuser['Mana'];
$usermindmg = $selectuser['mindmg'];
$usermaxdmg = $selectuser['maxdmg'];
$userdice = $selectuser['dice'];
$fightMonster = @mysql_fetch_array(@mysql_query("UPDATE fights SET Player1hp='$userhp', Player1mana='$usermana', Player1min='$usermindmg', Player1max='$usermaxdmg' WHERE User=".$_SESSION['Username'].""));
} else {
$selectuser = @mysql_fetch_array(@mysql_query("SELECT * FROM members WHERE Username=".$_SESSION['Username'].""));
$currently = $selectuser['Quest'];
$userhp = $selectuser['Life'];
$usermana = $selectuser['Mana'];
$usermindmg = $selectuser['mindmg'];
$usermaxdmg = $selectuser['maxdmg'];
$userdice = $selectuser['dice'];
$MonsterID = $_GET['monster'];
$selectMonster = @mysql_fetch_array(@mysql_query("SELECT * FROM monsters WHERE monsterID='$MonsterID'"));
$monstername = $selectMonster['monstername'];
$monsterlevel = $selectMonster['monsterlevel'];
$monsterdice = $selectMonster['monsterdice'];
$monsterhp = $selectMonster['monsterhp'];
$monstermana = $selectMonster['monstermana'];
$monsterarmor = $selectMonster['monsterarmor'];
$monstermindmg = $selectMonster['monstermindmg'];
$monstermaxdmg = $selectMonster['monstermaxdmg'];
$savefight = @mysql_fetch_array(@mysql_query("INSERT INTO fights SET User=".$_SESSION['Username'].", Player1hp='$userhp', Player1mana='$usermana', Player1min='$usermindmg', Player1max='$usermaxdmg', monstername='$monstername', monsterlevel='$monsterlevel', monsterdice='$monsterdice', monsterhp='$monsterhp', monstermana='$monstermana', monsterarmor='$monsterarmor', monstermindmg='$monstermindmg', monstermaxdmg='$monstermaxdmg'"));
}
?>
<div id="fightcontent">
<div id="fight1">
Health: <?php echo $userhp; ?> <br>
Mana: <?php echo $selectuser['Mana'];?><br>
Damage: <?php echo $selectuser['mindmg']; echo "-"; echo $selectuser['maxdmg'];?>
<br>
<br>
Dice: <?php echo $userdice; ?>
<br>
Quick Slots (3)
</div>
<div id="fight2">
Health: <?php echo $monsterhp; ?>
<br>
<?php
if($monstermana == "1") {
echo "Mana: $monstermana";
} else {}
?>
<?php
if($monsterarmor == "0") {
} else { echo "Armor: $monsterarmor"; }
?>
Damage: <?php echo $monstermindmg; echo "-"; echo $monstermaxdmg;?>
<br>
<br>
Dice: <?php echo $monsterdice; ?>
<br>
Spells / Quickslots
</div>
<div id="dice">
<?php
if($_POST['submit']) {
$selectuser = @mysql_fetch_array(@mysql_query("SELECT * FROM members WHERE Username=".$_SESSION['Username'].""));
$userdice = $selectuser['dice'];
$usermindmg = $selectuser['mindmg'];
$usermaxdmg = $selectuser['maxdmg'];
$MonsterID = $_GET['monster'];
$selectMonster = @mysql_fetch_array(@mysql_query("SELECT * FROM monsters WHERE monsterID='$MonsterID'"));
$monsterdice = $selectMonster['monsterdice'];
?>
<?php
if($userdice == 1){
$player1roll1 = rand(1,6);
$player1roll2 = 0;
$player1roll3 = 0;
}elseif($userdice == 2){
$player1roll1 = rand(1,6);
$player1roll2 = rand(1,6);
$player1roll3 = 0;
}elseif($userdice == 3){
$player1roll1 = rand(1,6);
$player1roll2 = rand(1,6);
$player1roll3 = rand(1,6);
}
?>
<?php
if($monsterdice == 1){
$player2roll1 = rand(1,6);
$player2roll2 = 0;
$player2roll3 = 0;
} elseif($monsterdice == 2){
$player2roll1 = rand(1,6);
$player2roll2 = rand(1,6);
$player2roll3 = 0;
}elseif($monsterdice == 3){
$player2roll1 = rand(1,6);
$player2roll2 = rand(1,6);
$player2roll3 = rand(1,6);
}
?>
<?php
$player1sum = $player1roll1 + $player1roll2 + $player1roll3;
$player2sum = $player2roll1 + $player2roll2 + $player2roll3;
if($player1sum > $player2sum) {
$playerdmg = rand($usermindmg,$usermaxdmg);
$monsterhpnew = $monsterhp - $playerdmg;
$fightMonster2 = @mysql_fetch_array(@mysql_query("UPDATE fights SET Player1hp='$userhp', Player1mana='$usermana', Player1min='$usermindmg', Player1max='$usermaxdmg', monsterdice='$monsterdice', monsterhp='$monsterhpnew', monstermana='$monstermana', monsterarmor='$monsterarmor' WHERE User=".$_SESSION['Username'].""));
echo "You hit ";
echo $monstername ;
echo ", with" ;
echo $playerdmg ;
echo "damage. remaining health:";
echo $monsterhpnew;
echo "<br>";
if($monsterhpnew < 1){
$updatefight = @mysql_fetch_array(@mysql_query("UPDATE members SET Fight=0 WHERE Username='$user'"));
$deletefight = @mysql_fetch_array(@mysql_query("DELETE FROM fights WHERE User='$user'"));
header("Location: quest.php?action=victory&ID=$currently");
echo "You killed him...";
}
}elseif($player2sum > $player1sum) {
echo "Player 2 won";
echo $player1sum ;
echo $player2sum ;
}else{
echo "Draw";
}
echo '<img src="images/dice/'.$player1roll1.'.gif" />'; //echo the image for roll 1 of player 1
echo '<img src="images/dice/'.$player1roll2.'.gif" />'; //echo the image for roll 2 of player 1
echo '<img src="images/dice/'.$player1roll3.'.gif" />'; //echo the image for roll 2 of player 1
echo " VS. ";
echo '<img src="images/dice/'.$player2roll1.'.gif" />'; //echo the image for roll 1 of player 2
echo '<img src="images/dice/'.$player2roll2.'.gif" />'; //echo the image for roll 2 of player 2
}else{
?>
<?php } ?>
<form method="post">
<input type="submit" name="submit" value="Roll dice" />
</form>
<?php } ?>
</div></div>