vmpl
Новичок
Выдаёт ошибку: Query failed : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'R2= where CHAR1_NAME='0' or CHAR2_NAME='0'' at line 1
Скажите что делать.
PHP:
<?php
$aBattleID = 0;
$aChar1 = "";
$aChar2 = "";
$aMove1 = 0;
$aMove2 = 0;
$aCurHealth1 = 0;
$aCurHealth2 = 0;
$aNickName = "";
$aOrder = 0; // какие мы в строке боя - CHAR1 или CHAR2 ?
$aOpponentNick = ""; // наш оппонент
if (!empty($_GET['NickName'])){
$aNickName = $_GET['NickName'];
}
if (!empty($_POST['NickName'])){
$aNickName = $_POST['NickName'];
}
if ($aNickName <> ""){
$aWhatStat = "";
$aWhatSkill = "";
// Узнаем характеристики персонажа
include "config.php";
$link = mysql_connect($mysql_host, $mysql_user, $mysql_password)
or die("Could not connect : " . mysql_error());
mysql_select_db($my_database) or die("Could not select database");
// узнаем каким номером мы находимсяя в строке боя CHAR1 или CHAR2, кто наш противник
// и кто уже успел сделать ход ?
$query = "SELECT BAT_ID,CHAR1_NAME,CHAR2_NAME,M1,M2 FROM battle WHERE CHAR1_NAME='$aNickName' OR CHAR2_NAME='$aNickName'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$aRow = mysql_fetch_array( $result);
$aBattleID = $aRow["BAT_ID"];
$aChar1 = $aRow["CHAR1_NAME"];
$aChar2 = $aRow["CHAR2_NAME"];
$aMove1 = $aRow["M1"];
$aMove2 = $aRow["M2"];
// определим некоторые параметры char1 и char2
// 1
$query = "SELECT * FROM users WHERE Nick_Name='$aChar1'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$aRow = mysql_fetch_array( $result);
$aStrength1 = $aRow["Character_Strength"];
$aEndurance1 = $aRow["Character_Endurance"];
$aCurHealth1 = $aRow["Character_CurHealth"];
// 2
$query = "SELECT * FROM users WHERE Nick_Name='$aChar2'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$aRow = mysql_fetch_array( $result);
$aStrength2 = $aRow["Character_Strength"];
$aEndurance2 = $aRow["Character_Endurance"];
$aCurHealth2 = $aRow["Character_CurHealth"];
// Поединок закончен ?
if ( ($aCurHealth1 == 0) || ($aCurHealth2 == 0) ){
// Устанавливаем статус 3 (чтоб посмотреть результаты)
$query = "UPDATE users set Character_Status = 3 where Nick_Name='$aChar1' or Nick_Name='$aChar2'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
// установим статусы после боя, согласно сохранившегося здоровья
$query = "UPDATE battle set R1=$aCurHealth1,R2=$aCurHealth2 where CHAR1_NAME='$aChar1' or CHAR2_NAME='$aChar2'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
print('<script>location.href="wait.php?NickName='.$aNickName.'&bat_id='.$aBattleID.'";</SCRIPT>');
}
if ( $aNickName == $aChar1 ){ // Мы под первым номером
$aShowEndurance1 = $aEndurance1;
$aShowHealth1 = $aCurHealth1;
$aShowEndurance2 = $aEndurance2;
$aShowHealth2 = $aCurHealth2;
$aOrder = 1;
$aOpponentNick = $aChar2;
// Проверим походил ли соперник
if (($aMove1 == 1) & ($aMove2 == 0)){
print('<script>location.href="wait.php?NickName='.$aNickName.'&bat_id='.$aBattleID.'";</SCRIPT>');
}
if ($aMove1 == 0){
// мы сделали ход!
if (!empty($_POST['attack'])) {
$aAttack = $_POST['attack'];
$aDefend = $_POST['defend'];
$query = "INSERT INTO battledetails(BAT_ID,CHAR_NAME,ATTACK,DEFEND) values ($aBattleID,'$aNickName',$aAttack,$aDefend)";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
// установим флаг хода для 1 игрока
$query = "UPDATE battle set M1=1 where CHAR1_NAME='$aNickName'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
print('<script>location.href="battle.php?NickName='.$aNickName.'";</SCRIPT>');
}
}
if (($aMove1 == 1) & ($aMove2 == 1)){ // расчитываем damage для обоих персонажей
CalcDamage($aChar1,$aChar2,$aBattleID); // считаем повреждения
print('<script>location.href="battle.php?NickName='.$aNickName.'";</SCRIPT>');
}
} else { // Мы под вторым номером
$aShowEndurance1 = $aEndurance2;
$aShowHealth1 = $aCurHealth2;
$aShowEndurance2 = $aEndurance1;
$aShowHealth2 = $aCurHealth1;
$aOrder = 2;
$aOpponentNick = $aChar1;
if (($aMove2 == 1) & ($aMove1 == 0)){
print('<script>location.href="wait.php?NickName='.$aNickName.'&bat_id='.$aBattleID.'";</SCRIPT>');
}
if ($aMove2 == 0){
// мы сделали ход!
if (!empty($_POST['attack'])) {
$aAttack = $_POST['attack'];
$aDefend = $_POST['defend'];
$query = "INSERT INTO battledetails(BAT_ID,CHAR_NAME,ATTACK,DEFEND) values ($aBattleID,'$aNickName',$aAttack,$aDefend)";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
// установим флаг хода для 1 игрока
$query = "UPDATE battle set M2=1 where CHAR2_NAME='$aNickName'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
print('<script>location.href="battle.php?NickName='.$aNickName.'";</SCRIPT>');
}
}
if (($aMove1 == 1) & ($aMove2 == 1)){ // расчитываем damage для обоих персонажей
CalcDamage($aChar1,$aChar2,$aBattleID); // считаем повреждения
print('<script>location.href="battle.php?NickName='.$aNickName.'";</SCRIPT>');
}
}
}
function CalcDamage($aChar1,$aChar2,$aBattleID){
// обнуляем флаги ходов игроков
$query = "UPDATE battle set M1=0, M2=0 where BAT_ID=$aBattleID";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
// параметры 1 игрока
$query = "SELECT * FROM users WHERE Nick_Name='$aChar1'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$aRow = mysql_fetch_array( $result);
$aStrength1 = $aRow["Character_Strength"];
$aCharLevel = $aRow["Character_Level"];
$aCurHealth1 = $aRow["Character_CurHealth"];
// параметры 2 игрока
$query = "SELECT * FROM users WHERE Nick_Name='$aChar1'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$aRow = mysql_fetch_array( $result);
$aStrength2 = $aRow["Character_Strength"];
$aCharLevel2 = $aRow["Character_Level"];
$aCurHealth2 = $aRow["Character_CurHealth"];
// кто куда ударил и что блокировал
// первый игрок
$query = "select * from battledetails WHERE CHAR_NAME='$aChar1' order by batdet_id DESC limit 1";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$aRow = mysql_fetch_array( $result);
$aAttack1 = $aRow["ATTACK"];
$aDefend1 = $aRow["DEFEND"];
// второй игрок
$query = "select * from battledetails WHERE CHAR_NAME='$aChar2' order by batdet_id DESC limit 1";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$aRow = mysql_fetch_array( $result);
$aAttack2 = $aRow["ATTACK"];
$aDefend2 = $aRow["DEFEND"];
// считаем повреждения, с учетом блоков
// куда бил игрок 1 и что блокировал игрок 2 ?
if ( ! Blocked($aAttack1,$aDefend2) ){
$aCurHealth2 = $aCurHealth2 - $aStrength1;
$aCurHealth2 = $aCurHealth2 < 0 ? 0 : $aCurHealth2;
$query = "UPDATE users set Character_CurHealth=$aCurHealth2 where Nick_Name='$aChar2'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
}
// куда бил игрок 2 и что блокировал игрок 1 ?
if ( ! Blocked($aAttack2,$aDefend1) ){
$aCurHealth1 = $aCurHealth1 - $aStrength2;
$aCurHealth1 = $aCurHealth1 < 0 ? 0 : $aCurHealth1;
$query = "UPDATE users set Character_CurHealth=$aCurHealth1 where Nick_Name='$aChar1'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
}
}
function Blocked($a,$d){
$def = array(1=>'12',2=>'23',3=>'34',4=>'41');
if( strpos($def[$d],$a) === false ){
$retv = false;
}else{
$retv = true;
}
return ($retv);
}
?>