質問編集履歴

3

改善

2016/09/06 02:12

投稿

a-_.
a-_.

スコア133

test CHANGED
File without changes
test CHANGED
File without changes

2

改善

2016/09/06 02:12

投稿

a-_.
a-_.

スコア133

test CHANGED
File without changes
test CHANGED
@@ -1,46 +1,78 @@
1
- 以下のコードを打ってみたんですが、調べても原因が把握できません
1
+ 以下のコードを打ってみたんですが、調べても原因が把握できません
2
2
 
3
- PHPコードの中にHTMLコードを入れたいんですが、<DOCUMENT HTML>を挿入する方法は合っているのでしょうか
3
+ PHPコードの中にHTMLコードを入れたいんですが、<DOCUMENT HTML>を挿入する方法は合っているのでしょうか
4
4
 
5
- 下記エラーはDOCUMENT~の行を指しています
5
+ 下記エラーはecho $comment~の行を指しています
6
6
 
7
- Parse error: syntax error, unexpected '<', expecting end of file in C:\XAMPP\htdocs\XXX.php on line 50
7
+ Notice: Undefined variable: time in C:\XAMPP\htdocs\XXX.php on line 21
8
+
9
+ array(2) {
10
+
11
+ ["name"]=>
12
+
13
+ string(6) "あい"
14
+
15
+ ["comment"]=>
16
+
17
+ string(9) "うえお"
18
+
19
+ }
20
+
21
+
22
+
23
+
8
24
 
9
25
  ```PHP
10
26
 
11
27
  <?php
12
28
 
13
- header('content-type: text/html; charset=UTF-8');
29
+ header('content-type: text/html; charset=UTF-8');
14
30
 
15
31
  ?>
16
32
 
17
33
  <html>
18
34
 
35
+ <DOCMENT HTML>
36
+
37
+ <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> </head>
38
+
39
+ <body>
40
+
41
+ <form method="post" action="XXX.php">
42
+
43
+ 名前:<input type="text" name="name">
44
+
45
+ 内容:<textarea name="comment" row="20" cols="20"> </textarea>
46
+
47
+ <input type="submit" value="投稿">
48
+
49
+ </form>
50
+
51
+ </body>
52
+
19
53
  <body>
20
54
 
21
55
  <?php
22
56
 
23
- $name = $_POST['name'];
57
+ $name = $_POST['name'];
24
58
 
25
- $comment = $_POST['comment'];
59
+ $comment = $_POST['comment'];
26
60
 
27
- $name = htmlspecialchars($name, ENT_QUOTES, 'UTF-8');
61
+ $name = htmlspecialchars($name, ENT_QUOTES, 'utf-8');
28
62
 
29
- $comment = htmlspecialchars($comment, ENT_QUOTES, 'UTF-8');
63
+ $comment = htmlspecialchars($comment, ENT_QUOTES, 'utf-8');
30
64
 
31
- echo $name, '<br>', PHP_EOL;
65
+ echo $name, '<br>', PHP_EOL;
32
66
 
33
- echo $comment, PHP_EOL;
67
+ echo $comment, $time, PHP_EOL;
34
-
35
- echo $time, PHP_EOL;
36
68
 
37
69
 
38
70
 
39
- echo '<pre>';
71
+ echo '<pre>';
40
72
 
41
- var_dump($_POST);
73
+ var_dump($_POST);
42
74
 
43
- echo '</pre>';
75
+ echo '</pre>';
44
76
 
45
77
 
46
78
 
@@ -56,13 +88,13 @@
56
88
 
57
89
  $mysqli = new mysqli($host, $user, $password, $dbname);
58
90
 
59
- if($mysqli->connect_error){
91
+ if($mysqli->connect_error){
60
92
 
61
- print("接続失敗:" . $mysqli->connect_error);
93
+ print("接続失敗:" . $mysqli->connect_error);
62
94
 
63
- exit();
95
+ exit();
64
96
 
65
- }
97
+ }
66
98
 
67
99
 
68
100
 
@@ -70,59 +102,41 @@
70
102
 
71
103
 
72
104
 
73
- $stmt = $mysqli->prepare('INSERT INTO XXX (name, comment) VALUES (?, ?)');
105
+ $stmt = $mysqli->prepare('INSERT INTO XXX (name, comment) VALUES (?, ?)');
74
106
 
75
- $stmt->bind_param('ss', $_POST['name'], $_POST['comment']);
107
+ $stmt->bind_param('ss', $_POST['name'], $_POST['comment']);
76
108
 
77
- $stmt->execute();
109
+ $stmt->execute();
78
110
 
79
111
 
80
112
 
81
- $query = 'SELECT * FROM XXX';
113
+ $query = 'SELECT * FROM XXX';
82
114
 
83
- $stmt = $mysqli->prepare($query);
115
+ $stmt = $mysqli->prepare($query);
84
116
 
85
- $stmt->execute();
117
+ $stmt->execute();
86
118
 
87
119
 
88
120
 
89
- $result = $mysqli->query('SELECT * FROM XXX ORDER BY time DESC');
121
+ $result = $mysqli->query('SELECT * FROM XXX ORDER BY time DESC');
90
122
 
91
- if($result){
123
+ if($result){
92
124
 
93
- while($row = $result->fetch_object()){
125
+ while($row = $result->fetch_object()){
94
126
 
95
- $name = htmlspecialchars($row->name);
127
+ $name = htmlspecialchars($row->name);
96
128
 
97
- $comment = htmlspecialchars($row->comment);
129
+ $comment = htmlspecialchars($row->comment);
98
130
 
99
- }
131
+ }
100
132
 
101
- }
133
+ }
102
134
 
103
135
 
104
136
 
105
137
  $mysqli->close();
106
138
 
107
139
 
108
-
109
- <DOCMENT HTML>
110
-
111
- <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head>
112
-
113
- <body>
114
-
115
- <form method="post" action="XXX.php">
116
-
117
- 名前:<input type="text" name="name">
118
-
119
- 内容:<textarea name="comment" row="20" cols="20"> </textarea>
120
-
121
- <input type="submit" value="投稿">
122
-
123
- </form>
124
-
125
- </body>
126
140
 
127
141
  ?>
128
142
 

1

改善

2016/07/13 02:37

投稿

a-_.
a-_.

スコア133

test CHANGED
@@ -1 +1 @@
1
- 何だか分から
1
+ 別のコードを挿入するやり方が分からない
test CHANGED
File without changes