0

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;

    }
Johnyy
  • 23
  • 5
  • You will have to send the value back to the server-side in order to save it in a `$_SESSION` variable. A good reading for you: [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Louys Patrice Bessette Jan 30 '22 at 20:28
  • PHP is server side language and JS is client side programing language. When client sends request to server then PHP works and generates content for client, which will work in browser. So PHP can include inside the content their "variable values" as a JS "variable value". JS variables can be used by PHP only after the request to the server. – E.H. Jan 30 '22 at 20:36

1 Answers1

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

other.php

<?php 
    $_SESSION['drewno'] = $_POST["drewno"];
?>