如何保存外键(SQL)

时间:2017-12-05 12:22:07

标签: php sql

$sql = "INSERT INTO deelnemer (Account_ID, BehaaldePunten, School_ID, Icon_ID) VALUES
          ('Account_ID', (SELECT ID FROM account WHERE Gebruikersnaam = '$name'),
          0,
          ('School_ID', (SELECT ID FROM school WHERE Naam = '$school'),
          ('Icon_ID', (SELECT ID FROM icon WHERE ID = 1))
          INNER JOIN account ON deelnemer.Account_ID = account.ID,
          INNER JOIN school ON deelnemer.School_ID = school.ID";
          $result = $connection->prepare($sql);
          $result->execute();
嘿,伙计们,我对SQL很陌生。我需要保存一行包含一些外键并且我已经尝试了一些东西,但似乎没有任何效果。我希望你能帮助我xX

这是错误消息:

  

致命错误:未捕获的异常' PDOException'与消息   ' SQLSTATE [42000]:语法错误或访问冲突:1064您有   SQL语法错误;查看与您的手册相对应的手册   MariaDB服务器版本,用于在&JOAH; INNER JOIN附近使用正确的语法   帐户ON deelnemer.Account_ID = account.ID,INNER JO'在第6行'在   C:\ xampp \ htdocs \ GameBattle \ test \ Register_Modal.php:36堆栈跟踪:#0   C:\ XAMPP \ htdocs中\ GameBattle \测试\ Register_Modal.php(36):   PDOStatement-> execute()#1   C:\ XAMPP \ htdocs中\ GameBattle \测试\ login.php中(84):   require_once(' C:\ xampp \ htdocs ...')#2 {main}引入   第36行的C:\ xampp \ htdocs \ GameBattle \ test \ Register_Modal.php

1 个答案:

答案 0 :(得分:0)

尝试替换:

('Account_ID', (SELECT ID FROM account WHERE Gebruikersnaam = '$name')
          0,
          ('School_ID', (SELECT ID FROM school WHERE Naam = '$school'),

只是:

(SELECT ID FROM account WHERE Gebruikersnaam = '$name',
          0,
 SELECT ID FROM school WHERE Naam = '$school'
etc... )