Skip to content
Advertisement

Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row:

during the realization of a project I encountered this problem can you help me please Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (bdd_sql.publications, CONSTRAINT publications_ibfk_1 FOREIGN KEY (auteur) REFERENCES utilisateurs (id) ON DELETE CASCADE ON UPDATE CASCADE) in C:xampphtdocsmini_projetclass.php:107 Stack trace: #0 C:xampphtdocsmini_projetclass.php(107): PDO->query(‘INSERT INTO pub…’) #1 C:xampphtdocsmini_projettransformation.php(24): Connexion->query(‘INSERT INTO pub…’) #2 {main} thrown in C:xampphtdocsmini_projetclass.php on line 107

enter image description here

code php

JavaScript

database

JavaScript

Advertisement

Answer

To prevent SQL injection, it is recommended that you never use variables directly in your connections, and you can use it as a key value to be safe from some attacks. like this:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement