I have this code to delete the data of the database in which the name is equal to the one chosen in the combobox, whose code And the second. But for some reason I can not figure out which one is not working. Can you help me?
....
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if (isset($_POST['botao_apagar']))
{
$cbnome= trim($_POST['cbMedicos']);
$stmt = $conn->prepare("DELETE * FROM Medicos WHERE nome= '".$cbnome."' ");
$stmt->execute();
// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
?>
combobox code:
<label for="cbMedicos">Selecione um Médico</label>
<select id="cbMedicos" name="cbMedicos">
<option>Selecione...</option>
<?php while($prod = $data->fetch_assoc()) {
echo '<option value="'.$prod['txtid'].'">'.$prod['txtNome'].'</option>';
$meujson[$prod['txtid']] = $prod; // coleciona as linhas no $meujson
}
?>
</select>