質問編集履歴

1

コード追加

2017/06/20 03:33

投稿

kazoogon
kazoogon

スコア281

test CHANGED
File without changes
test CHANGED
@@ -147,3 +147,69 @@
147
147
  }
148
148
 
149
149
  ```
150
+
151
+
152
+
153
+ signup部分のmodel追加します
154
+
155
+ ```
156
+
157
+ function signup($link,$username,$password,$password2){
158
+
159
+ if(isset($_SESSION['user_id']) === TRUE){
160
+
161
+ header('省略');
162
+
163
+ }else{
164
+
165
+ if($username === ""){
166
+
167
+ $error[] = "*please fill in username";
168
+
169
+ }else if($password === ""){
170
+
171
+ $error[] = "please fill in password";
172
+
173
+ }else if($password !== $password2){
174
+
175
+ $error[] = "please fill in same password";
176
+
177
+ }
178
+
179
+ if(count($error) === 0){
180
+
181
+ $password = password_hash($password,PASSWORD_DEFAULT);
182
+
183
+ $query = 'INSERT INTO user(username,password)
184
+
185
+ VALUES(\''.$username.'\',\''.$password.'\')';
186
+
187
+ return insert_action($link,$query);
188
+
189
+ }
190
+
191
+ }
192
+
193
+ }
194
+
195
+ function insert_action($link,$query){
196
+
197
+ global $error_for_me;
198
+
199
+ if(($result = mysqli_query($link,$query))===FALSE){
200
+
201
+ return FALSE;
202
+
203
+ $error_for_me[]="insert_action失敗".$query;
204
+
205
+ }else{
206
+
207
+ return TRUE;
208
+
209
+ }
210
+
211
+ }
212
+
213
+ password_hash関数使用したsignup部分の関数も載せときます
214
+
215
+ ```