# Storing Jquery Variable into Php database

**URL:** <https://www.phphelp.com/t/storing-jquery-variable-into-php-database/33426>\
**Category:** Beginners - Learning PHP\
**Created:** [April 30, 2021, 7:34pm UTC](https://www.phphelp.com/t/storing-jquery-variable-into-php-database/33426 "2021-04-30T19:34:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mercury](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/e95f7d/32.png) [@Mercury](https://www.phphelp.com/u/Mercury)\
**Post date:** [April 30, 2021, 7:34pm UTC](https://www.phphelp.com/t/storing-jquery-variable-into-php-database/33426/1 "2021-04-30T19:34:42Z")

</div>

```auto
jQuery(document).ready(function ($) {

  $("#coin").click(function () {
    var flipResult = Math.random();
    $("#coin").removeClass();
    setTimeout(function () {
        var coinResult = " Heads"
      if (flipResult <= 0.5) {
        $("#coin").addClass("heads");
        console.log(coinResult);
      } else {
    var coinResult = "Tails"
        $("#coin").addClass("tails");
        console.log(coinResult);

      }
      $('#table_of_results').append('<tr><td>' + coinResult + '</td></tr>');

 for(i=0;i<1;i++){

    $.ajax({ type:"post", url:"server.php?p=add", data: coinResult, datatype: "text", success: function(postresult){ console.log("success");} })

}
```

Got the coin to flip and append table element correctly but it wont post to server any idea why?

---

<div class="post-metadata">

**Author:** ![whispers](https://www.phphelp.com/letter_avatar_proxy/v4/letter/w/858c86/32.png) [@whispers](https://www.phphelp.com/u/whispers)\
**Post date:** [April 30, 2021, 8:20pm UTC](https://www.phphelp.com/t/storing-jquery-variable-into-php-database/33426/2 "2021-04-30T20:20:23Z")

</div>

You’ll probably have to post the contents of server .php…since that is the area you mention is NOT working.

You posted the code/routine that you said IS working…so its of no use really.

In your server.php file… ensure you are at least getting the variable/data…

at that point you’ll know if its a data passing issue, or a database writing/connection issue.
