I'm trying to get the user's choice in a <option>
tag.
The multiple <option>
tags are generated from data from the database.
Here's the form:
<form action="mudaVideo.php" method="post">
<label for="sel1">escolher o vídeo</label>
<select class="form-control" name="apagar">
<?php
$sql = "SELECT * FROM video ORDER BY idvideo";
$result = mysqli_query($conn,$sql) or trigger_error("SQL", E_USER_ERROR);
while ($list = mysqli_fetch_assoc($result)) {
$idvideo = $list["idvideo"];
$titulo = $list["titulo"];
$subtitulo = $list["subtitulo"];
$link = $list["link"];
echo '<option>'.$titulo.'</option>';
} // end while
?>
<option>wow ate me passo</option> -->
</select>
<button type="submit" name="apagar" class="btn btn-primary" id="enviar" style="background-color:transparent; color:black;">apagar vídeo</button>
</div>
</form>
Here's my php:
if(isset($_POST['apagar'])) {
$id = $_POST['apagar'];
echo 'a escolha foi ' . $id . '!';
$sql = "DELETE FROM video
WHERE idvideo='".$id."'";
$result = mysqli_query($conn, $sql);
if ($conn->query($sql) === TRUE)
{
}
else
{
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
When I try to echo the value of $id, it's empty, so something wrong is escaping me.
Thanks in advance