mercredi 17 avril 2019

How to insert multiple rows to mysql using php form when checkbox is ticked in the row

i Have a PHP form where im sending to MYSQL DB fields: ID, NAME, CITY I have another form where im editing whole list. What id like to do is to populate the same NAME (choosing from list) to every row when checkbox is ticked.

Form.php

<form method="post" action="submit.php" >
<select name="name" id="name"><option type="text" name="name" value="<?php echo $name ?>"><?php echo $name ?></option></select>
<select name="city" id="city"><option type="text" name="city" value="<?php echo $city ?>"><?php echo $city ?></option></select>
<input type="checkbox" name="check[<?php echo $id ?>]" value="<?php echo $id ?>">
<button type="submit" name="update">Update</button>
</form>

submit.php

if (isset($_POST['update'])) {
    foreach($_POST['check'] as $key=>$value){
    $id = $_POST['id'];
        $name = $_POST['id'][$key];
    $city = $_POST['city'];
        mysqli_query($db, "UPDATE table SET name='$name', city='$city' WHERE id=$id");
}

It would be awsome to tick checkbox to those rows where i want to have the same defined NAME and submit it.




Aucun commentaire:

Enregistrer un commentaire