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

質問編集履歴

4

a顎文

2016/10/07 16:29

投稿

sekaizyu
sekaizyu

スコア14

title CHANGED
File without changes
body CHANGED
@@ -34,7 +34,7 @@
34
34
  }
35
35
  }
36
36
 
37
- $sql=sprintf('INSERT INTO stage SET mapchip="%s"',mysql_real_escape_string("$array"));
37
+ $sql=sprintf('INSERT INTO stage SET mapchip="%s"',mysql_real_escape_string("$stringbond"));
38
38
  mysqli_query($db,$sql) or die(mysqli_error($db));
39
39
 
40
40
  //print $sql;

3

修正

2016/10/07 16:28

投稿

sekaizyu
sekaizyu

スコア14

title CHANGED
File without changes
body CHANGED
@@ -8,22 +8,16 @@
8
8
  今のコードが動かない原因を教えてもらえると嬉しいです。
9
9
 
10
10
  ```PHP
11
+
12
+ //unity側から送られたデータ
13
+ //chipnum[0]~chipnum[164]
14
+
11
15
  <?php
12
16
  $postData = file_get_contents("php://input");
13
17
  $inputData = json_decode(stripcslashes($postData));
14
18
  //データベースに接続
15
19
  $db=mysqli_connect('localhost','root','','unity') or die(mysqli_connect_error());
16
20
 
17
- //受取リスト
18
- //chipnum[15*11]
19
- //width
20
- //height
21
- $width=0;
22
- $height=0;
23
- //受け取ったデータをPHPの変数に代入
24
- $width=$_POST['width'];
25
- $height=$_POST['height'];
26
-
27
21
  //受信した配列をテキストに変更
28
22
 
29
23
  //文字列を結合先用の変数
@@ -33,6 +27,7 @@
33
27
  for($i=0;$i<165;$i++)
34
28
  {
35
29
  //エラーの原因
30
+ //なぜこうしたかというと全部文字列化されたので
36
31
  $chipnumname='chipnum'.'['."$i".']';
37
32
  if(isset($_POST["$chipnumname"])){
38
33
  $stringbond.=$_POST["$chipnumname"].",";

2

書き直し

2016/10/07 02:48

投稿

sekaizyu
sekaizyu

スコア14

title CHANGED
File without changes
body CHANGED
@@ -15,30 +15,40 @@
15
15
  $db=mysqli_connect('localhost','root','','unity') or die(mysqli_connect_error());
16
16
 
17
17
  //受取リスト
18
- //$inputData->chipnum[15*11]
18
+ //chipnum[15*11]
19
+ //width
20
+ //height
21
+ $width=0;
22
+ $height=0;
23
+ //受け取ったデータをPHPの変数に代入
24
+ $width=$_POST['width'];
25
+ $height=$_POST['height'];
26
+
19
27
  //受信した配列をテキストに変更
28
+
29
+ //文字列を結合先用の変数
20
- $array="";
30
+ $stringbond="";
21
31
  $chipnumname="";
22
32
  //配列を代入
23
- for($i=0;$i<(15*11);$i++)
33
+ for($i=0;$i<165;$i++)
24
34
  {
25
35
  //エラーの原因
26
36
  $chipnumname='chipnum'.'['."$i".']';
27
- //チェックしてあったら結合
28
37
  if(isset($_POST["$chipnumname"])){
29
- //結合しているつもり
30
- $array.=$_POST["$chipnumname"].",";
38
+ $stringbond.=$_POST["$chipnumname"].",";
31
39
  }
32
40
  }
33
41
 
34
42
  $sql=sprintf('INSERT INTO stage SET mapchip="%s"',mysql_real_escape_string("$array"));
35
43
  mysqli_query($db,$sql) or die(mysqli_error($db));
36
44
 
45
+ //print $sql;
46
+
47
+
37
48
  exit();
38
49
  ?>
39
50
  ```
40
51
 
41
- 今のままですとからのデータがmapchipに挿入されます
52
+ 今のままですとのデータがmapchipに挿入されます
42
53
  何も入ってないものです 空白です
43
-
44
- ![イメジ説明](a78f781acf51d60c904dd3659177467e.png)
54
+ エラはPHPとUnityなどで連携しているのでPHP側のエラーはブラックボックスです

1

結果の画像を添付しました

2016/10/07 02:45

投稿

sekaizyu
sekaizyu

スコア14

title CHANGED
File without changes
body CHANGED
@@ -36,4 +36,9 @@
36
36
 
37
37
  exit();
38
38
  ?>
39
- ```
39
+ ```
40
+
41
+ 今のままですとからのデータがmapchipに挿入されます
42
+ 何も入ってないものです 空白です
43
+
44
+ ![イメージ説明](a78f781acf51d60c904dd3659177467e.png)