Here is the situation I have already connected to the database. I bring the list to a function. It looks like this -

image

Now we select the list, it is loaded from the database.

image

Here is the part code itself -

<?php function fetchGenres() { $db = new Connection(); $db->open(); $genres = $db->runQuery("SELECT * FROM clubgenre"); $db->close(); $genresArr = array(); while ($row = $genres->fetch_assoc()) { $genresArr[$row["code"]] = $row["category"]; } return $genresArr; } function showCategory($genresArr) { echo '<p><div class="row"> <select name="sweets" class="input-field col s12"> <option value="" disabled selected>Choose the ganre</option>'; foreach ($genresArr as $key => $value) { echo '<option value="'. $key .'">'. $value .'</option>'; } // Go to next key next($genresArr); echo ' </select> <input type="submit" name="entergenre" value="Delete Genre" class=" waves-effect waves-green btn-flat"> </div></p> '; } showCategory(fetchGenres()); ?> 

Here is the question itself - When you click on the button, it is necessary that the category selected by the user be deleted from the database.
Here is oak with oak i. If you can write a part, and if not, then explain in stages. I would be incredibly grateful, I’m actually been tormenting for 2 days, first to make a list from the base, now with it. I do not even fully understand why it works for me.

    1 answer 1

     $db = new PDO(); $genre = filter_input(INPUT_POST, 'sweets', FILTER_VALIDATE_INT); $sth = $db->prepare("DELETE FROM clubgenre WHERE code=?;"); $sth->execute([$genre]); 

    Naturally, the solution needs to be adapted to your class of work with the database.