0

So basically I want to be able to pass a variable from Javascript to php dynamically and without $_GET and preferably without cookies, so I tried using html DOM to change the .value of the html hidden element and then posting it but it won't recognise the value has changed.

    for(i=0;i<60; i++) {
        pen.push(<?php 
            $ii += 1;
            $sql=mysqli_query($connection, "SELECT Quantity from stockinventory where ID = '$ii'");
        while($row = $sql->fetch_assoc()) {
            echo(json_encode($row['Quantity']));
                    }

        ?>);
    }
         //fix this

    function subStock(cuanto, id) {

        pen[id] = pen[id]-1;
        document.getElementById(id).innerHTML = pen[id];
        document.getElementByName(id).value = pen[id];
    }

    function addStock(cuanto, id) {
        pen[id] = parseInt(pen[id])+1;
        document.getElementById(id).innerHTML = pen[id];
        document.getElementByName(id).value = pen[id];
    }
</script>

    $search = mysqli_query($connection, "SELECT * from stockinventory WHERE categody LIKE '%$empanada%'");
    echo("<form action='admin.php' method='POST'>
        <input type='submit' name='Juan'>");
    while($row = $search->fetch_assoc()) {
        echo("<div class='wrapper' id='wrap'>
                <div class = 'dynamo' style= background-image:url(".$row['imagee'].")>
                    <h2>".$row['Name']."</h2>
                        <div class='slider' id='slider'>
                            <p id='rat'>".$row['Description']."</p>
                            <button type='button' onClick='subStock(".$row['Quantity'].",". $i.")' id= 'jose' name= 'Alma'>-</button>
                            <a id=".$i.">".$row['Quantity']."</a>
                            <button type='button' onClick='addStock(".$row['Quantity'].",". $i.")' id= 'jose' name= 'Alma'>+</button>
                            <form method='POST' action='admin.php'>
                            <input type='hidden' id= G".$i." value = 10 name = ".$i." >
                            </form>
                        </div>
                </div>
            </div>");
        $i+=1;
    }
if(isset($_POST['Juan'])) 
{
    //for($c = 0; $c<39; $c++ ) {
    $c = 1;
    $quant = $_POST[$c];
    echo($_POST[$c]);
    $dql = mysqli_query($connection, "UPDATE stockinventory
        SET Quantity = $quant
        WHERE ID = '$c'");
}
  • Does this answer your question? [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) – Rotimi May 20 '20 at 07:20
  • 1
    `
    ` inside `
    ` is invalid. Your hidden field "belongs" to your second form, the form you submit knows nothing about it. Don't forget to close your first form
    – brombeer May 20 '20 at 07:23
  • Ahhh thank you so much I didn't even realise I had that one up there thank you!! –  May 20 '20 at 07:27
  • That didn't work :(, but thank you anyways, It's posting the placeholder value but not the javascript replacement –  May 20 '20 at 07:36

0 Answers0