0
I have this code to erase the data from the database where the name is the same as the one chosen on the combobox, whose code and the second. But for some reason I can’t figure out which one isn’t working. They can 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>
Actually it is taking the id of the combobox and not the name. If so replace
value="'.$prod['txtid']
forvalue="'.$prod['txtNome']
or in your query you delete by ID– adventistaam