Home > Enterprise >  How to set js variable in php and save it into data base
How to set js variable in php and save it into data base

Time:01-31

I create new variable and next code is add value to this variable. This code have Load (working) and dont working save i try to fix search google and i dont know

<?php
    session_start();
    ?>

    <script type="text/javascript">

    var drzewo = 0;
    var ustdrzewo = 1;
 
    
    /* L O A D */
    
    function wczytaj() {
    drzewo = <?php echo $_SESSION['drewno']; ?>;
    ustdrzewo = <?php echo $_SESSION['ustdrzewo']; ?>;
    document.getElementById("drzewo").innerHTML = drzewo;
    document.getElementById("ustdrzewo").innerHTML = ustdrzewo;

    }
    /* S A V E */
    function zapisz() {
        <?php
    $_SESSION['drewno'] = "<script type='text/javascript'> document.getElementById('drzewo').innerHTML = drzewo; </script>"
        ?>
        window.location.href = "zapis.php"
    }

function addwood() {
        drzewo  =ustdrzewo
        document.getElementById("drzewo").innerHTML = drzewo;

    }

CodePudding user response:

<script type="text/javascript">
//include jquery
$.post( "other.php", { drewno: drzewo } );
</script>

other.php

<?php 
    $_SESSION['drewno'] = $_POST["drewno"];
?>
  •  Tags:  
  • Related