Do not query DB SQL

0

I'm doing a project, in most cases the consultations are    they perform normally and correctly, but on 2 occasions (one of them is)    he performs the query, he tries to print the query and nothing happens.     

$mysqli = new mysqli("localhost","root","1234","basededatos");

$ID_PERSONA = $_SESSION['ID'];
$Comentario = 
htmlspecialchars(mysqli_real_escape_string($mysqli,$_POST['Comentario']));
$ID_POST = htmlspecialchars(mysqli_real_escape_string($mysqli,$_GET['ID']));

$mysqli->query("INSERT INTO comentariosforo (ID_Persona, ID_Post, 
Comentario) VALUES ('$ID_PERSONA', '$ID_POST', '$Comentario')");


header("Location:http://localhost/Foro/Post.php?ID=$ID_POST");
?>
    
asked by JuamBer 21.06.2018 в 10:01
source

1 answer

2

As Alfredo has told you if you have the Id in the database as primary key and autoincrementable you do not have to give it value, the database will do it automatically.

If the id of the session for example is 3, it is normal that there is already a row in the table with id 3, so you can not save another row with the id 3 in the database, since the id exists and is primary key and autoincrementable.

    
answered by 21.06.2018 / 10:57
source