0

ayer hice una consulta para agregar un input o textarea dependiando un input radio. Ahora estoy tratando de guardar uno de esos datos y solo me deja guardad uno.

<?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">&#91;text&#93;
<input type="radio" name="tipo" class="i-radio" value="img">&#91;image&#93;<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>

2
  • Por lo que se ve, intentas mandar dos valores a la misma columna (tipo nota: post e img) Entonces tus opciones son: agregar una tercera columna o mandar únicamente 2 parámetros en lugar de 3.
    – Pajaro5
    el 4 sep. 2018 a las 4:10
  • Si, voy a tener que hacer eso... me la complique solo... je, gracias
    – Santiaggo
    el 4 sep. 2018 a las 13:44

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.