teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

SQL文だけ記載しました。

2019/11/30 15:47

投稿

shunei
shunei

スコア5

title CHANGED
File without changes
body CHANGED
@@ -3,20 +3,18 @@
3
3
  何がいけないのかご教授していただけたら幸いです。↓登録用のデータベースのカラム
4
4
  ![![イメージ説明](1277cd12aeb255584e085b2c712a22c2.png)](83982ddd482b1d941f617cf118c387d5.png)
5
5
  コード
6
- <?php
7
6
 
7
+
8
8
  // データを登録するSQL作成
9
9
  $sql = "INSERT INTO MEMBER (id,NAME,KANA,TEL,MAIL,YEAR,SEX,MAGAGINE,PASS_TMP,PASSWORD) VALUES(0,'$_POST[your_name]','$_POST[your_kanaName]','$_POST[your_number]','$_POST[your_mail]',$_POST[birth_year],$_POST[gender],$_POST[agreement],'テスト','テスト')";
10
-
11
- }
10
+
12
11
 
13
12
 
14
13
 
15
14
  ### 発生している問題・エラーメッセージ
16
15
 
17
16
  ```
18
- 会員登録ありがとうございました。
19
- 書き込み失敗しました。
17
+ データベース登録できない
20
18
  ```
21
19
 
22
20
  ###試したこと

1

SQL文だけ記載しました。

2019/11/30 15:47

投稿

shunei
shunei

スコア5

title CHANGED
File without changes
body CHANGED
@@ -4,227 +4,14 @@
4
4
  ![![イメージ説明](1277cd12aeb255584e085b2c712a22c2.png)](83982ddd482b1d941f617cf118c387d5.png)
5
5
  コード
6
6
  <?php
7
- var_dump($_POST);
8
7
 
9
- //データベースの接続情報
10
- define('DB_HOST','localhost');
11
- define('DB_USER','root');
12
- define('DB_PASS','root');
13
- define('DB_NAME','TECKIS');
14
-
15
-
16
-
17
- //変数の初期化
18
- $page_flag = 0;
19
- $clean = array();
20
- $error_message = array();
21
-
22
-
23
- //入力確認ページ
24
- if( !empty($_POST['btn_confirm'])) {
25
-
26
- $page_flag = 1;
27
-
28
-
29
- // if( empty($_POST['agreement'])){
30
-
31
- // $_POST['agreement'] = '送付しない';
32
-
33
-
34
- // }
35
- } elseif (!empty($_POST['btn_submit'])) {
36
-
37
- $page_flag = 2;
38
-
39
- // //メール送信機能
40
- // //変数とタイムゾーンを初期化
41
- // $auto_reply_subject = null;
42
- // $auto_reply_text = null;
43
- // $date_default_timezone_set('Asia/Tokyo');
44
-
45
- //件名を設定
46
- // $auto_reply_subject = '会員登録ありがとうございました';
47
-
48
- // 本文を設定
49
- // $auto_reply_text = "会員の仮登録しました。以下の情報で登録いたします\n\n";
50
- // $auto_reply_text .= "お問い合わせ日時:" . date("Y-m-d H:i") . "\n";
51
- // $auto_reply_text .= "名前:" . $_POST['your_name'] . "\n";
52
- // $auto_reply_text .= "カナ:" . $_POST['your_kanaName'] . "\n";
53
- // $auto_reply_text .= "メールアドレス:" . $_POST['your_mail'] . "\n";
54
- // $auto_reply_text .= "電話:" . $_POST['your_number'] . "\n";
55
- // $auto_reply_text .= "生まれ年:" . $_POST['birth_year'] . "\n";
56
- // $auto_reply_text .= "性別:" . $_POST['gender'] . "\n";
57
- // $auto_reply_text .= "メールマガジン:" . $_POST['agreement'] . "\n";
58
- // $auto_reply_text .= "Tech IS 事務局";
59
-
60
- // // // メール送信
61
- // mb_send_mail( $_POST['your_mail'], $auto_reply_subject, $auto_reply_text);
62
-
63
-
64
-
65
-
66
- // データベースに接続
67
- $mysqli = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME);
68
-
69
- //接続エラーの確認
70
- if( $mysqli->connect_errno ) {
71
- $error_message[] = '書き込みに失敗しました。 エラー番号 '.$mysqli->connect_errno.' : '.$mysqli->connect_error;
72
- } else {
73
-
74
- // 文字コード設定
75
- $mysqli->set_charset('utf8');
76
-
77
8
  // データを登録するSQL作成
78
9
  $sql = "INSERT INTO MEMBER (id,NAME,KANA,TEL,MAIL,YEAR,SEX,MAGAGINE,PASS_TMP,PASSWORD) VALUES(0,'$_POST[your_name]','$_POST[your_kanaName]','$_POST[your_number]','$_POST[your_mail]',$_POST[birth_year],$_POST[gender],$_POST[agreement],'テスト','テスト')";
79
10
 
80
11
  }
81
- // データを登録
12
+
82
- $res = $mysqli->query($sql);
83
- var_dump($res);
84
- if( $res ) {
85
- $success_message = 'メッセージを書き込みました。';
86
- } else {
87
- $error_message[] = '書き込みに失敗しました。';
88
- }
89
13
 
90
- // データベースの接続を閉じる
91
- $mysqli->close();
92
- }
93
- ?>
94
14
 
95
- <!DOCTYPE html>
96
- <html lang="ja">
97
- <head>
98
- <title>会員登録フォーム</title>
99
- <style rel="stylesheet" type="text/css">
100
-
101
-
102
-
103
- <body>
104
- <?php if( $page_flag === 1): ?>
105
- <h1>会員登録フォーム</h1>
106
- <form method="post" action="">
107
- <div class="element_wrap">
108
- <label>名前</label>
109
- <p><?php echo $_POST['your_name']; ?></p>
110
- </div>
111
-
112
- <div class="element_wrap">
113
- <label>カナ</label>
114
- <p><?php echo $_POST['your_kanaName']; ?></p>
115
- </div>
116
-
117
- <div class="element_wrap">
118
- <label>電話</label>
119
- <p><?php echo $_POST['your_number']; ?></p>
120
- </div>
121
-
122
- <div class="element_wrap">
123
- <label>mail</label>
124
- <p><?php echo $_POST['your_mail']; ?></p>
125
- </div>
126
-
127
- <div class="element_wrap">
128
- <label>生まれ年</label>
129
- <p><?php echo $_POST['birth_year']; ?></p>
130
- </div>
131
-
132
- <div class="element_wrap">
133
- <label>性別</label>
134
- <p><?php if( $_POST['gender'] == "1" ){ echo '男性'; }
135
- else{ echo '女性'; } ?></p>
136
- </div>
137
-
138
- <div class="element_wrap">
139
- <label>メールマガジンに同意する</label>
140
- <p><?php if( $_POST['agreement'] === "1" ){ echo '同意する'; }
141
- else{ echo '同意しない'; } ?></p>
142
- </div>
143
- <input type="submit" name="btn_back" value="戻る">
144
- <input type="submit" name="btn_submit" value="送信">
145
- <input type="hidden" name="your_name" value="<?php echo $_POST['your_name']; ?>">
146
- <input type="hidden" name="your_kanaName" value="<?php echo $_POST['your_kanaName']; ?>">
147
- <input type="hidden" name="your_number" value="<?php echo $_POST['your_number']; ?>">
148
- <input type="hidden" name="your_mail" value="<?php echo $_POST['your_mail']; ?>">
149
- <input type="hidden" name="birth_year" value="<?php echo $_POST['birth_year']; ?>">
150
- <input type="hidden" name="gender" value="<?php echo $_POST['gender']; ?>">
151
- <input type="hidden" name="agreement" value="<?php echo $_POST['agreement']; ?>">
152
-
153
- </form>
154
-
155
- <?php elseif( $page_flag === 2 ): ?>
156
- <p>会員登録ありがとうございました。</p>
157
- <?php if( !empty($success_message) ): ?>
158
- <p class="success_message"><?php echo $success_message; ?></p>
159
- <?php endif; ?>
160
- <?php if( !empty($error_message) ): ?>
161
- <ul class="error_message">
162
- <?php foreach($error_message as $value): ?>
163
- <li><?php echo $value; ?></li>
164
- <?php endforeach; ?>
165
- </ul>
166
- <?php endif; ?>
167
-
168
-
169
- <?php else: ?>
170
- <body>
171
- <h1>会員登録フォーム</h1>
172
-
173
-
174
-
175
- <form method="post" action="">
176
- <div class="element_wrap">
177
- <label>名前</label>
178
- <input type="text" name="your_name" value="<?php if( !empty($_POST['your_name']) ){ echo $_POST['your_name']; } ?>">
179
- </div>
180
-
181
- <div class="element_wrap">
182
- <label>カナ</label>
183
- <input type="text" name="your_kanaName" value="<?php if( !empty($_POST['your_kanaName']) ){ echo $_POST['your_kanaName']; } ?>">
184
- </div>
185
-
186
- <div class="element_wrap">
187
- <label>電話</label>
188
- <input type="text" name="your_number" value="<?php if( !empty($_POST['your_number']) ){ echo $_POST['your_number']; } ?>">
189
- </div>
190
-
191
- <div class="element_wrap">
192
- <label>mail</label>
193
- <input type="text" name="your_mail" value="<?php if( !empty($_POST['your_mail']) ){ echo $_POST['your_mail']; } ?>">
194
- </div>
195
-
196
- <div class="element_wrap">
197
- <label>生まれ年</label>
198
- <select name="birth_year">
199
- <?php foreach(range(1920,2020) as $year): ?>
200
- <?php if( !empty($_POST['birth_year']) && $_POST['birth_year']==$year ): ?>
201
- <option value="<?=$year?>" selected><?=$year?></option>
202
- <?php else:?>
203
- <option value="<?=$year?>"><?=$year?></option>
204
- <?php endif; ?>
205
- <?php endforeach; ?>
206
- </select>
207
- </div>
208
-
209
- <div class="element_wrap">
210
- <label>性別</label>
211
- <label for="gender_male"><input id="gender_male" type="radio" name="gender" value="1" <?php if( !empty($_POST['gender']) && $_POST['gender'] === "1" ){ echo 'checked'; } ?>>男性</label>
212
- <label for="gender_female"><input id="gender_female" type="radio" name="gender" value="2"<?php if( !empty($_POST['gender']) && $_POST['gender'] === "2" ){ echo 'checked'; } ?>>女性</label>
213
- </div>
214
-
215
- <div class="element_wrap">
216
- <label>メールマガジン</label>
217
- <label for="agreement"><input id="agreement" type="checkbox" name="agreement" value="1" <?php if( !empty($_POST['agreement']) && $_POST['agreement'] === "1" ){ echo 'checked'; } ?>>メールマガジン送付</label>
218
- </div>
219
-
220
- <input type="submit" name="btn_confirm" value="入力内容を確認する">
221
- </form>
222
-
223
- <?php endif; ?>
224
- </body>
225
- </html>
226
-
227
-
228
15
  ### 発生している問題・エラーメッセージ
229
16
 
230
17
  ```