Yesterday I made a query to add an input or textarea depending on a radio input. Now I'm trying to save one of those data and just leave me one.
<?php
if(isset($_POST['add'])){
if(!empty($_POST['tipo']) && !empty($_POST['img']) && !empty($_POST['txt'])){
$add = $conn->prepare("INSERT INTO notas (tipo, tiponota) VALUES (:tipo, :tiponota)");
$add->bindValue(':tipo', ($_POST['tipo']));
$add->bindValue(':tiponota', ($_POST['post']));
$add->bindValue(':tiponota', ($_POST['img']));
$add->execute();
echo "bien";
}
else{
echo "mal";
}
}
?>
/* oculto los elementos */
input.i-text, textarea {display: none;}
/* lo muestros si está seleccionado value=imagen */
input.i-radio[value="img"]:checked ~ input.i-text {display: block;}
/* lo muestros si está seleccionado value=texto */
input.i-radio[value="txt"]:checked ~ textarea {display: block;}
<form action="" method="POST">
<input type="radio" name="tipo" class="i-radio" value="txt">[text]
<input type="radio" name="tipo" class="i-radio" value="img">[image]<br>
<input type="text" name="img" class="i-text inputI" placeholder="URL image"><br>
<textarea name="post" placeholder="Nota de credito"></textarea><br>
<button name="add">Agregar</button>
</form>