When connecting to Postman, I am able to insert data correctly. Here is my query in postman:
{<br> "Company2_ID_Company2": "120",<br> "Company2_DHS6_ID": "144", <br> "Company2_ID_Main": "153",<br> "Retake_ID_Main": "120", <br> "Retake_ID": "120", <br> "Retake1_ID": "120",<br> "Retake1_ID_Retake1": "120",<br> "Pass": "Yes"<br> } However, the error is
<br /> <b>Fatal error</b>: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near <b>'Company2_ID_Company2 = '120', Company2_DHS6_ID = '144', Company2_ID_Main = '153''</b> at line 17 in C:\XAMPP\htdocs\API_Demo2\Models\Post.php:212 Stack trace: #0 C:\XAMPP\htdocs\API_Demo2\Models\Post.php(212): PDOStatement->execute() #1 C:\XAMPP\htdocs\API_Demo2\Post\Create.php(43): Post->create() #2 {main} thrown in <b>C:\XAMPP\htdocs\API_Demo2\Models\Post.php</b> on line <b>212</b><br /> Whats strange is that whenever I change the numbers in the query, they show up correctly in the error.
Here is my PHP code with the entire query:
$query = 'SELECT sandbox.company2.Company2_ID_Company2 AS Company2_ID_Company2, sandbox.company2.Company_DHS6_ID AS Company2_DHS6_ID, sandbox.main.Retake_ID_Main AS Retake_ID_Main, sandbox.main.Company2_ID_Main AS Company2_ID_Main, sandbox.retake.Retake_ID AS Retake_ID, sandbox.retake.Retake1_ID AS Retake1_ID, sandbox.retake1.Retake1_ID_Retake1 AS Retake1_ID_Retake1, sandbox.retake1.Pass AS Pass FROM ' . $this->table . ' company2 JOIN main ON sandbox.Company2.Company2_ID_Company2 = sandbox.main.Company2_ID_Main JOIN retake ON sandbox.main.Retake_ID_Main = sandbox.retake.Retake_ID JOIN retake1 ON sandbox.retake.Retake1_ID = sandbox.retake1.Retake1_ID_Retake1' . 'INSERT INTO ' . $this->table . ' SET Company2_ID_Company2 = :Company2_ID_Company2, Company2_DHS6_ID = :Company2_DHS6_ID, Company2_ID_Main = :Company2_ID_Main, Retake_ID_Main = :Retake_ID_Main, Retake_ID = :Retake_ID, Retake1_ID = :Retake1_ID, Retake1_ID_Retake1 = :Retake1_ID_Retake1, Pass = :Pass';
insertsyntax is inverted.INSERT INTO table (columns) select values...See dev.mysql.com/doc/refman/8.0/en/insert-select.html:parameterwhen the values are coming from theSELECT, not query parameters?