callesson Posted April 20, 2010 Share Posted April 20, 2010 Hello folks! I got the suggestion to use AJAXS for my problem, update sql without refreshing. But im not that into javascript or Ajax right now so I would like some help! What I have is: A game were you can fight Player vs Player. I have this submit button that will make the other player loose Health. So if I press it my friend will loose Health, I will display it but my friend need to update before he will be able to see the change. And I want it to change right away. Right now when someone presses the submit(arena.php) they will be redicted to a_temp.php where the sql statement is, then you will be redirected to arena.php. Arena.php <form action='a_temp.php' method='post'><input type='submit' name='uatt' value='Uatt'/></form> a_temp.php <?php session_start(); if (!isset($_POST['uatt'])) { header("Location:landskapdone.php"); exit; } include('connect.php'); $query = mysql_query("SELECT * FROM chars WHERE user='$_SESSION[user]'"); while($row = mysql_fetch_array($query)) { $ulevel = $row['Level']; $uname = $row['Name']; $uhp = $row['HP']; $ump = $row['MP']; $uHpmax = $row['Hpmax']; $uMpmax = $row['Mpmax']; $udamage = $row['Damage']; $udamagemax = $row['Damagemax']; $query = mysql_query("SELECT * FROM chars WHERE User='$_SESSION[from]'"); while($row = mysql_fetch_array($query)) { $olevel = $row['Level']; $oname = $row['Name']; $ohp = $row['HP']; $omp = $row['MP']; $oHpmax = $row['Hpmax']; $oMpmax = $row['Mpmax']; $select = mysql_query("SELECT * FROM arena_inv WHERE a_to='$_SESSION[user]' OR a_from='$_SESSION[user]'"); while($row = mysql_fetch_array($select)) { $acc = $row['acc']; $from = $row['a_from']; $to = $row['a_to']; if(isset($_POST['uatt']) && $to ==$_SESSION['user']) { $num = rand(0,2) ; switch ($num) { case 0: $makedamage = mysql_query("UPDATE chars SET hp=hp -$udamage WHERE user='$_SESSION[from]'"); break; case 1: $makedamage = mysql_query("UPDATE chars SET hp=hp -$udamagemax WHERE user='$_SESSION[from]'"); break; case 2: break; } $takemana = mysql_query("UPDATE chars SET mp=mp -5 WHERE user='$_SESSION[user]'"); header("Location:arena.php"); } elseif(isset($_POST['uatt']) && $from ==$_SESSION['user']) { $num = rand(0,2) ; switch ($num) { case 0: $makedamage = mysql_query("UPDATE chars SET hp=hp -$udamage WHERE user='$_SESSION[to]'"); break; case 1: $makedamage = mysql_query("UPDATE chars SET hp=hp -$udamagemax WHERE user='$_SESSION[to]'"); break; case 2: break; } $takemana = mysql_query("UPDATE chars SET mp=mp -5 WHERE user='$_SESSION[user]'"); header("Location:arena.php"); } if($ohp<=0) { $honor= mysql_query("UPDATE chars SET Honor=Honor +1 WHERE user='$_SESSION[user]'"); header("Location:Youwon.php"); } if($uhp<=0) { header("Location:Youlost.php"); } } } } ?> I guess i dont need redirect when its dynamic ? Link to comment https://forums.phpfreaks.com/topic/199115-update-with-ajax/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.