0

I have a table where i store the current value, and i have a button that should take the current value and subtract 100 from it and save the new value in the database.

<div class="container">
    <div class="row">
        <div class="col-md-12">
            <p>
            <center>
                <button onClick="updateHp()">ATTACK</button>
            </center>
            </p>
        </div>
    </div>
</div>

here is how i get my data (i echoed it out and its okay)

$result = $conn1 ->query($sql);
$row = $result->fetch_assoc();
$boss_name = $row['name'];
$boss_hp =  $row['hp'];

<script>
var newHp =<?php echo $boss_hp;?> - 100;
function updateHp(){
}
</script>

Im a bit clueless how to go about the ajax script, i know i need to make the calcualtion nad pass it over to a update.php but here i where i got stuck.

mheonyae
  • 581
  • 2
  • 8
  • 24
  • Firstly, there is a typo. It should be ` – Milan Chheda Jun 20 '17 at 18:18
  • You are expected to try to **write the code yourself**. After [**doing more research**](https://meta.stackoverflow.com/q/261592/1011527) if you have a problem **post what you've tried** with a **clear explanation of what isn't working** and provide [a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). Read [How to Ask](http://stackoverflow.com/help/how-to-ask) a good question. Be sure to [take the tour](http://stackoverflow.com/tour) and read [this](https://meta.stackoverflow.com/q/347937/1011527). – Jay Blanchard Jun 20 '17 at 18:18
  • [jQuery AJAX Basics](http://jayblanchard.net/basics_of_jquery_ajax.html) – Jay Blanchard Jun 20 '17 at 18:19

0 Answers0