I am solving a system where I need for design reasons that a field is equal to the value of the id that it takes at the moment of inserting the record ... The field is numeric but when I want to do this I get an error:
$stmt = $conexion -> prepare("INSERT INTO avisos_comentarios (fecha, idaviso, idpregunta, idrespuesta, idusuario, usuario, comentario, aprobado) VALUES (:fecha, :idaviso, id, :idrespuesta, :idusuario, :usuario, :sDetalle, :aprobado)");
$stmt->bindValue(":fecha", $fecha);
$stmt->bindValue(":idaviso", $idAviso);
$stmt->bindValue(":idrespuesta", $idRespuesta);
$stmt->bindValue(":idusuario", $idUsuario);
$stmt->bindValue(":usuario", $usuario);
$stmt->bindValue(":comentario", $sDetalle);
$stmt->bindValue(":aprobado", $aprobado);
$stmt->execute();
The id question has to be equal to the id at the moment of inserting the record
The error that throws me is that there is a variable that is not defined ...
if I assign to each assignment the: front and a certain field I match it with the id ... I would have to walk ... or not?
EXTENSION It is a question and answer system housed in a single table.
when they ask a question, take the id from the table and the answer = 0
later when they answer the question (I take the id question) and answer and in idrespuesta I store the id of the table ...
The questions will have different id's of users while the answers will be from the same user (obviously) because he is the one who posted the notice ...
I get the list that is done simply:
FROM [BD] where idaviso = 20 order by idpregunta, idrespuesta
a pavada ... the only thing I need is to see how I duplicate that id value ... hehehehe