JS Script POST's a different/wrong ID to another file in PHP

76
September 24, 2021, at 1:20 PM

My Problem: I have a dropdown menu in a column, which (or should) updates either a yes or no in the DB table.

It's working in two other columns where you can choose only one option, but now it's kinda weird.

When I want to change the 'ja' to a 'nein' in the column with the 'bestellnr' (ID) 107, it's updating the column with the ID 109. But if I'm updating 109, it's really updating 109. When I'm choosing a number smaller than other ones, it updating the other ones first...

I tried to make the change function in the script with the ID of the <select> and changed every name and so on, but I don't now where the mistake is..

This is my select Code in the columns:

  <?php if($row['geliefert']=="Ja"){?>
    <form id="lieferung_1" method="post">
      <select class="lieferung_dropdown_ja" id="lieferung_dropdown_ja" name="geliefert">
        <option class="lieferung_position" name="lieferung_position" id="lieferung_position" value="<?php echo $row['bestellnr']; ?>"><?php echo $row['geliefert']; ?></option>
        <option class="lieferung_option_Nein" name="lieferung_option_Nein" id="lieferung_option_Nein" value="Nein">Nein</option>
        <option class="lieferung_option_storniert" name="lieferung_option_storniert" id="lieferung_storniert" value="storniert">storniert</option>
      </select>
    </form>
<?php  }?>

The JS Script:

<script type="text/javascript">
    $(function () {
        $(".lieferung_dropdown_ja").change(function (e) {
            e.preventDefault();
            var choice = $(this).val();
            var nr = $(lieferung_position).val();
            var info = {
                choice: choice,
                nr: nr
            };
            $.ajax({
                type: "POST",
                url: "addlistone.php",
                data: info,
                success: function (response) {
                    $('#customers').html(response);
                }
            });
        });
    });
</script>

And the update query in the other file:

$lieferung_ja = (isset($_POST['choice']) && !empty($_POST['choice'])) ? $_POST['choice'] : null;
$bestellnr_ja = (isset($_POST['nr']) && !empty($_POST['nr'])) ? $_POST['nr'] : null;
$update_geliefert_ja = mysqli_query($connection,"UPDATE bestellung SET geliefert='$lieferung_ja' WHERE bestellnr='$bestellnr_ja'");
$result_geliefert_ja = $connection->query($update_geliefert_ja);
READ ALSO
How to access torch (flashlight) using javascript or jquery?

How to access torch (flashlight) using javascript or jquery?

I am using the html5-qrcode barcode scanner library based on zxing and everything is working fine

73
LinkedLIst and Switch Case Java to add middle string [closed]

LinkedLIst and Switch Case Java to add middle string [closed]

Want to improve this question? Add details and clarify the problem by editing this post

61
SVG `fill` overlaps `stroke`

SVG `fill` overlaps `stroke`

Having a circle it has fill and strokeBut I see that fill color overlaps little bit stroke

82
Get MIN, MAX values from a linking table

Get MIN, MAX values from a linking table

I have 3 tables in a MYSQL DB

75