質問編集履歴
4
var_dump($row);した結果を追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -110,8 +110,6 @@
|
|
110
110
|
|
111
111
|
わからない部分は $check_login_query からです
|
112
112
|
|
113
|
-
|
114
|
-
|
115
113
|
``` php
|
116
114
|
|
117
115
|
<?php
|
@@ -159,3 +157,13 @@
|
|
159
157
|
?>
|
160
158
|
|
161
159
|
```
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
var_dump($row);した結果
|
164
|
+
|
165
|
+
```php
|
166
|
+
|
167
|
+
array(24) { [0]=> string(1) "3" ["id"]=> string(1) "3" [1]=> string(8) "Chandler" ["first_name"]=> string(8) "Chandler" [2]=> string(4) "Bing" ["last_name"]=> string(4) "Bing" [3]=> string(13) "chandler_bing" ["username"]=> string(13) "chandler_bing" [4]=> string(18) "Chandler@gmail.com" ["email"]=> string(18) "Chandler@gmail.com" [5]=> string(32) "e04857f0b448a8d84176da365bca0da6" ["password"]=> string(32) "e04857f0b448a8d84176da365bca0da6" [6]=> string(10) "2019-05-15" ["signup_date"]=> string(10) "2019-05-15" [7]=> string(54) "assets/images/profile_pics/defaults/head_deep_blue.png" ["profile_pic"]=> string(54) "assets/images/profile_pics/defaults/head_deep_blue.png" [8]=> string(1) "0" ["num_posts"]=> string(1) "0" [9]=> string(1) "0" ["num_likes"]=> string(1) "0" [10]=> string(2) "no" ["user_closed"]=> string(2) "no" [11]=> string(1) "," ["friend_array"]=> string(1) "," }
|
168
|
+
|
169
|
+
```
|
3
$_SESSION['username'] = $username; の抜けていた$を足しました!
test
CHANGED
File without changes
|
test
CHANGED
@@ -44,7 +44,7 @@
|
|
44
44
|
|
45
45
|
|
46
46
|
|
47
|
-
$_SESSION['username'] = username;
|
47
|
+
$_SESSION['username'] = $username;
|
48
48
|
|
49
49
|
header("Location: index.php");
|
50
50
|
|
@@ -142,7 +142,7 @@
|
|
142
142
|
|
143
143
|
|
144
144
|
|
145
|
-
$_SESSION['username'] = username;
|
145
|
+
$_SESSION['username'] = $username;
|
146
146
|
|
147
147
|
header("Location: index.php");
|
148
148
|
|
2
わからない部分の詳細や、タイトルを変更しました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
なぜSQLの列を取得して、配列に入れる必要があるのか?
|
test
CHANGED
@@ -1,8 +1,106 @@
|
|
1
|
-
phpでツイッターのクローンを教材を見ながら作成しています。
|
1
|
+
phpでツイッターのクローンをUdemyの教材を見ながら作成しています。
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
+
教材でどうしても意味の分からない部分があったので、教えていただきたいです。
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
```PHP
|
10
|
+
|
11
|
+
$check_database_query = mysqli($con, "SELECT * FROM users WHERE email = '$email' AND password = '$password'");
|
12
|
+
|
13
|
+
$check_login_query = mysqli_num_rows($check_database_query);
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
```
|
18
|
+
|
19
|
+
|
20
|
+
|
5
|
-
|
21
|
+
SQLのテーブルに入っているユーザー情報を取り出して、変数に入れて、行数がいくつかを変数に格納していました。
|
22
|
+
|
23
|
+
ここで一つ目の質問なのですが、mysqli_num_rowsは「結果の行数を取得する」という意味とマニュアルに書いてあったのですが、これは「変数の情報と適応する情報が入った列が何行あるのか?」を取得するという認識で正しいのでしょうか?
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
その後、
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
```php
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
if($check_login_query == 1) {
|
40
|
+
|
41
|
+
$row = mysqli_fetch_array($check_database_query);
|
42
|
+
|
43
|
+
$username = $row['username'];
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
$_SESSION['username'] = username;
|
48
|
+
|
49
|
+
header("Location: index.php");
|
50
|
+
|
51
|
+
exit();
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
まず、If文で、先ほど得た行数が1、つまり、正常に情報がテーブルに入っているかどうかを確認しています。
|
62
|
+
|
63
|
+
次に、mysqli_fetch_array関数を使って、結果の行を連想配列で取得しています。
|
64
|
+
|
65
|
+
ここで二つめの質問なのですが、ここで取得した連想配列とは、下のようなものでしょうか?
|
66
|
+
|
67
|
+
```php
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
$row = array(
|
72
|
+
|
73
|
+
"email" => "test@gmail.com",
|
74
|
+
|
75
|
+
"password" => "**********"
|
76
|
+
|
77
|
+
);
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
その後、
|
84
|
+
|
85
|
+
```php
|
86
|
+
|
87
|
+
$username = $row['username'];
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
と続くのですが、$row['username']というのはどのような意味なのでしょうか?
|
92
|
+
|
93
|
+
予想では、ユーザーネームに入っている配列の「username」キーの情報を変数に格納するという意味だと思うのですが・・・・
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
最後の質問なのですが、exit();は必要なのでしょうか?
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
6
104
|
|
7
105
|
|
8
106
|
|
1
コードを付け足しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -7,6 +7,10 @@
|
|
7
7
|
|
8
8
|
|
9
9
|
わかる方いらっしゃいましたら、教えて下さい!!
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
わからない部分は $check_login_query からです
|
10
14
|
|
11
15
|
|
12
16
|
|