I made a fight with the bot:
1) We beat:
<?php session_start(); $host = ''; $username = ''; $password = ''; $db_name = ''; $tbl_name = ''; mysql_connect($host, $username, $password) or die("can't connect"); mysql_select_db($db_name) or die(mysql_error()); mysql_query("SELECT * FROM $tbl_name"); mysql_query("UPDATE `enemy` SET `username`='".$_SESSION['username']."' ")or die(mysql_error()) ; $sql = mysql_query("INSERT INTO `battle` (img,name,level,life,atk,def,type,username) SELECT img,name,level,life,atk,def,type,username FROM `enemy` ORDER BY RAND() LIMIT 1")or die(mysql_error()); ?> <table> <tr> <TD><?php $result = mysql_query("SELECT * FROM startpoke WHERE id_poke = '".$_SESSION['id']."'")or die("can't connect") ; while( $row = mysql_fetch_array( $result ) ){ echo "<br>{$row['name_poke']}" ; echo " - {$row['level']} lvl"; echo "<br>{$row['img']}"; ?> <div style='width:250px;border:0px solid black;margin-center: 0%;'> <div align="left" style='center:0px;width:100%;background-color:green;'><?php echo "{$row['all_life']}"; echo "/{$row['life']}"; ?></div> <div style='width:250px;border:0px solid black;margin-center: 0%;'> <div align="left" style='center:0px;width:100%;background-color:blue;'><?php echo "{$row['exp']}"; ?></div> </TD> <TD><a href="javascript: onClick=win1=window.open('def.php','width=650,height=400,scrollbars=yes');return true;"><?php echo "{$row['atk']}"; } ?></a></TD> <TD><?php $res = mysql_query("SELECT * FROM battle WHERE username = '".$_SESSION['username']."' LIMIT 1")or die(mysql_error()); while( $row = mysql_fetch_array( $res ) ){ echo "<br>{$row['name']}" ; echo " - {$row['level']} lvl"; echo "<br> {$row['img']}";?> <div style='width:250px;border:0px solid black'> <div align="left" style='center:0px;width:100%;background-color:green;'><?php echo "{$row['life']}"; } ?></div></TD> </tr> </table> </center> </body> </html>
2) They beat us:
<?php session_start(); $host = $username = $password = $db_name = mysql_connect($host, $username, $password) or die(mysql_error()) ; mysql_select_db($db_name) or die(mysql_error()); $res = mysql_query("SELECT * FROM battle WHERE username='".$_SESSION['username']."'"); $pok = mysql_fetch_array($res); $sql = mysql_query("SELECT * FROM startpoke WHERE id_poke='".$_SESSION['id']."'"); $row = mysql_fetch_array($sql); if($pok['life'] < 0 ){ mysql_query("DELETE FROM `pokelight620`.`battle` WHERE `battle`.`username` = '".$_SESSION['username']."'")or die(mysql_error()) ; echo "Победа! <a href='loc=1.php'>Уйти</a>"; } else{ if($row['life'] > 0 ){ mysql_query("UPDATE `startpoke` SET `life`=`life`-3 WHERE id_poke='".$_SESSION['id']."'")or die(mysql_error()) ; mysql_query("UPDATE `battle` SET `life`=`life`-3 WHERE username='".$_SESSION['username']."'")or die(mysql_error()) ; echo "<script>location.href='fight.php';</script>"; } else{ mysql_query("UPDATE `startpoke` SET `life`=0 WHERE id_poke='".$_SESSION['id']."'")or die(mysql_error()) ; mysql_query("DELETE FROM `pokelight620`.`battle` WHERE `battle`.`username` = '".$_SESSION['username']."'")or die(mysql_error()) ; echo "Вы проиграли! <a href='loc=1.php'>Уйти</a>"; } } ?>
Sorry for the big code, just for something else! So, when the fight.php page (this is when we are beaten) is updated, another bot is entered and constantly has to beat different bots, but only one is needed, and so I decided to check it all with the user's login, for example: the user started the battle and attacked the bot, in the table where the bot itself weighs there is a username column where the user's login is entered, which means that you need to pull out the bot with the user's login, but since the fight.php page is constantly updated, bots with the user's login are constantly added, and you need to pull only one I decided to do If the record with the user's login name already means not enters a new robot, the question of how to do it? if possible with the code, thanks in advance!