質問編集履歴

2

追記を記載

2020/04/04 11:04

投稿

ke_i
ke_i

スコア8

test CHANGED
File without changes
test CHANGED
@@ -107,3 +107,63 @@
107
107
  他にどのように調べれば解決できるのか、何が足りないのか、そもそも考え方が合っているかなどを教えていただいたいです。
108
108
 
109
109
  すみませんがアドバイスよろしくお願いします。
110
+
111
+
112
+
113
+ ### 追記
114
+
115
+ 現在のSQLコードになります。
116
+
117
+ ```
118
+
119
+ $sql = 'INSERT INTO articles (name, content, category_id, user_id, tag_id)
120
+
121
+ VALUES (:name, :content, :category_id, :user_id, :tag_id)';
122
+
123
+ $sth = $pdo -> prepare($sql);
124
+
125
+ $sth -> bindValue(':name', $_SESSION['title'],PDO::PARAM_STR);
126
+
127
+ $sth -> bindValue(':content', $_SESSION['contents'],PDO::PARAM_STR);
128
+
129
+ $sth -> bindValue(':category_id', $_SESSION['category_id'], PDO::PARAM_INT);
130
+
131
+ $sth -> bindValue(':user_id', $_SESSION['user_id'], PDO::PARAM_INT);
132
+
133
+ $sth -> bindValue(':tag_id', $_SESSION['tag_id'], PDO::PARAM_INT);
134
+
135
+ $sth -> execute();
136
+
137
+ ```
138
+
139
+ テーブル中身は以下になります。
140
+
141
+
142
+
143
+ - articles
144
+
145
+ ```
146
+
147
+ id, name, content, category_id, user_id, tag_id
148
+
149
+ ```
150
+
151
+
152
+
153
+ - article_tag
154
+
155
+ ```
156
+
157
+ article_id, tag_id
158
+
159
+ ```
160
+
161
+
162
+
163
+ - tags
164
+
165
+ ```
166
+
167
+ id, name
168
+
169
+ ```

1

名前付きと疑問符のsql文が逆になっていたため修正しております

2020/04/04 11:04

投稿

ke_i
ke_i

スコア8

test CHANGED
File without changes
test CHANGED
@@ -46,7 +46,7 @@
46
46
 
47
47
  ```
48
48
 
49
- SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
49
+ SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`blog`.`articles`, CONSTRAINT `articles_ibfk_3` FOREIGN KEY (`tag_id`) REFERENCES `tag_article` (`article_id`))
50
50
 
51
51
  ```
52
52
 
@@ -54,7 +54,7 @@
54
54
 
55
55
  ```
56
56
 
57
- SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`blog`.`articles`, CONSTRAINT `articles_ibfk_3` FOREIGN KEY (`tag_id`) REFERENCES `tag_article` (`article_id`))
57
+ SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
58
58
 
59
59
  ```
60
60