質問編集履歴
2
しつもんへんこう
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
フォームの値を
|
1
|
+
フォームの値を受け取りたい
|
test
CHANGED
@@ -1,57 +1,5 @@
|
|
1
|
-
受け取ったIDとtxtファイルに格納されているidの商品情報が等しければその等しいIDのtxtの内容を上書きしたいのですがうまくいきません。どのようにすればよいですか?
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
```php
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
フォームの値を受け取りたい
|
10
2
|
|
11
3
|
$json = file_get_contents("php://input");
|
12
4
|
|
13
5
|
$json_data = json_decode($json, true);
|
14
|
-
|
15
|
-
$ID = $json_data['userid'];
|
16
|
-
|
17
|
-
$product = $json_data['product'];
|
18
|
-
|
19
|
-
$color = $json_data['color'];
|
20
|
-
|
21
|
-
$filearr = file('product.txt');
|
22
|
-
|
23
|
-
$newLines = array();
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
foreach ($filearr as $no => $val) {
|
28
|
-
|
29
|
-
$cols = explode(",", $val);
|
30
|
-
|
31
|
-
$keyval = explode("=", $cols[0]);
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
if ($keyval[1] == $ID) {
|
36
|
-
|
37
|
-
$newLines[$ID] = $str;
|
38
|
-
|
39
|
-
} else {
|
40
|
-
|
41
|
-
$newLines[] = $val;
|
42
|
-
|
43
|
-
}
|
44
|
-
|
45
|
-
}
|
46
|
-
|
47
|
-
$fp = fopen("product.txt", "w");
|
48
|
-
|
49
|
-
fwrite($fp, implode("", $newLines));
|
50
|
-
|
51
|
-
fclose($fp);
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
```
|
1
setumeibunntuika
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,45 +6,51 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
+
<?php
|
10
|
+
|
9
11
|
$json = file_get_contents("php://input");
|
10
12
|
|
11
13
|
$json_data = json_decode($json, true);
|
12
14
|
|
13
|
-
$ID = $json_data['id'];
|
15
|
+
$ID = $json_data['userid'];
|
14
16
|
|
15
17
|
$product = $json_data['product'];
|
16
18
|
|
17
19
|
$color = $json_data['color'];
|
18
20
|
|
19
|
-
$
|
21
|
+
$filearr = file('product.txt');
|
22
|
+
|
23
|
+
$newLines = array();
|
20
24
|
|
21
25
|
|
22
26
|
|
23
|
-
foreach ($filearr as $no => $val) {
|
27
|
+
foreach ($filearr as $no => $val) {
|
24
28
|
|
25
|
-
$cols = explode(",", $val);
|
29
|
+
$cols = explode(",", $val);
|
26
30
|
|
27
|
-
$keyval = explode("=", $cols[0]);
|
31
|
+
$keyval = explode("=", $cols[0]);
|
28
32
|
|
29
33
|
|
30
34
|
|
31
|
-
if ($keyval[1] == $ID) {
|
35
|
+
if ($keyval[1] == $ID) {
|
32
36
|
|
33
37
|
$newLines[$ID] = $str;
|
34
38
|
|
35
|
-
} else {
|
39
|
+
} else {
|
36
40
|
|
37
|
-
$newLines[] = $val;
|
41
|
+
$newLines[] = $val;
|
38
42
|
|
39
|
-
}
|
43
|
+
}
|
40
44
|
|
41
|
-
}
|
45
|
+
}
|
42
46
|
|
43
|
-
$fp = fopen("
|
47
|
+
$fp = fopen("product.txt", "w");
|
44
48
|
|
45
|
-
fwrite($fp, implode("", $newLines));
|
49
|
+
fwrite($fp, implode("", $newLines));
|
46
50
|
|
47
|
-
fclose($fp);
|
51
|
+
fclose($fp);
|
52
|
+
|
53
|
+
|
48
54
|
|
49
55
|
|
50
56
|
|