質問編集履歴

2

Tittleの修正

2021/07/21 02:05

投稿

nguyenseiji
nguyenseiji

スコア156

test CHANGED
@@ -1 +1 @@
1
- WPFを使ったWebAPIでPOSTしたJSON情報がWEB側(PHP)表示されない
1
+ WPFを使ったWebAPIでPOSTしたJSON情報がWEB側PHPを使ってデータベースにうまく追加ない
test CHANGED
File without changes

1

PHPコードの追加

2021/07/21 02:05

投稿

nguyenseiji
nguyenseiji

スコア156

test CHANGED
File without changes
test CHANGED
@@ -43,3 +43,77 @@
43
43
  }
44
44
 
45
45
  ```
46
+
47
+
48
+
49
+ ```php
50
+
51
+ <?php
52
+
53
+
54
+
55
+ try{
56
+
57
+ require "./private/database.php";
58
+
59
+ $DBH->beginTransaction();
60
+
61
+
62
+
63
+
64
+
65
+ $url = $_SERVER['REQUEST_URI'];
66
+
67
+
68
+
69
+ $json = $url;
70
+
71
+ $json = mb_convert_encoding($json, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN');
72
+
73
+ $arr = json_decode($json,true);
74
+
75
+ $FirstIndex = $arr["age"];
76
+
77
+ $SecondIndex = $arr["name"];
78
+
79
+
80
+
81
+ $STMT = $DBH->prepare('INSERT INTO debug(Age,Name) VALUE(?,?)');
82
+
83
+ $STMT->bindValue(1,$FirstIndex,PDO::PARAM_INT);
84
+
85
+ $STMT->bindValue(2,$SecondIndex,PDO::PARAM_STR);
86
+
87
+ $STMT->execute();
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+ $DBH->commit();
102
+
103
+ }catch(Exception $ERROR){
104
+
105
+ $DBH->rollBack();
106
+
107
+ print $ERROR;
108
+
109
+ exit();
110
+
111
+ }
112
+
113
+
114
+
115
+
116
+
117
+ ?>
118
+
119
+ ```