質問編集履歴

1

改善

2016/09/09 02:22

投稿

a-_.
a-_.

スコア133

test CHANGED
File without changes
test CHANGED
@@ -25,3 +25,285 @@
25
25
 
26
26
 
27
27
  因みに調べていると「http://~.js」という書き方があるのを把握したんですが、この書き方はどういうリンクの貼り方なんでしょうか
28
+
29
+
30
+
31
+ 追記
32
+
33
+ 上がa.php
34
+
35
+ ```PHP
36
+
37
+ <?php
38
+
39
+ header("Content-Type: application/json; charset=UTF-8");
40
+
41
+
42
+
43
+ if ($_POST['bbs'] == "post") {
44
+
45
+ require ("XXX1.php");
46
+
47
+ $p_obj = new Post();
48
+
49
+ $p_obj -> name = $_POST['name'];
50
+
51
+ $p_obj -> comment = $_POST['comment'];
52
+
53
+ $p_obj -> post();
54
+
55
+ } elseif ($_POST['bbs'] == "update") {
56
+
57
+ require ("XXX2.php");
58
+
59
+ $u_obj = new Update();
60
+
61
+ $u_obj -> name = $_POST['name'];
62
+
63
+ $u_obj -> comment = $_POST['comment'];
64
+
65
+ $u_obj -> chk = $_POST['chk'];
66
+
67
+ $u_obj -> update();
68
+
69
+ } elseif ($_POST['bbs'] == "delete") {
70
+
71
+ require ("XXX3.php");
72
+
73
+ $d_obj = new Delete();
74
+
75
+ $d_obj -> chk = $_POST['chk'];
76
+
77
+ $d_obj -> delete();
78
+
79
+ }
80
+
81
+
82
+
83
+ require("XXX4.php");
84
+
85
+ $l_obj = new List_table;
86
+
87
+ $data = $l_obj -> list();
88
+
89
+ echo json_encode($data);
90
+
91
+ exit;
92
+
93
+ ?>
94
+
95
+ ```
96
+
97
+ 下がb.php
98
+
99
+ ```
100
+
101
+ <html>
102
+
103
+ <head>
104
+
105
+ <meta charset="utf-8">
106
+
107
+ <meta http-equiv="Content-Script-Type" content="text/javascript">
108
+
109
+ <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
110
+
111
+ <script>
112
+
113
+ $(function() {
114
+
115
+ $('input[name=bbs]').click(function(e) {
116
+
117
+ change($(this).prop('id'));
118
+
119
+ });
120
+
121
+ change($('input[name=bbs]:checked').prop('id'));
122
+
123
+ });
124
+
125
+ function condition() {
126
+
127
+ if ($('#r1').prop('checked')) {
128
+
129
+ with($('#name')) {
130
+
131
+ if (val().length >= 10) {
132
+
133
+ alert("ERROR");
134
+
135
+ return false;
136
+
137
+ }
138
+
139
+ if (val() === "") {
140
+
141
+ alert("ERROR");
142
+
143
+ return false;
144
+
145
+ }
146
+
147
+ }
148
+
149
+ with($('#comment')) {
150
+
151
+ if (val().length >= 300) {
152
+
153
+ alert("ERROR");
154
+
155
+ return false;
156
+
157
+ }
158
+
159
+ if (val() === "") {
160
+
161
+ alert("ERROR");
162
+
163
+ return false;
164
+
165
+ }
166
+
167
+ }
168
+
169
+ }
170
+
171
+ if($('#r2').prop('checked')||$('#r3').prop('checked')) {
172
+
173
+ if ($('[name="chkid[]"]:checked').length == 0) {
174
+
175
+ window.alert("ERROR");
176
+
177
+ return false;
178
+
179
+ }
180
+
181
+ }
182
+
183
+ return true;
184
+
185
+ }
186
+
187
+ function change(myid) {
188
+
189
+ var sendlist = {
190
+
191
+ "r1":{"text":"投稿",checkflg:true},
192
+
193
+ "r2":{"text":"更新",checkflg:false},
194
+
195
+ "r3":{"text":"削除",checkflg:false},
196
+
197
+ };
198
+
199
+ $('#send').val(sendlist[myid].text);
200
+
201
+ $('[name="chkid[]"]').prop('disabled',sendlist[myid].checkflg);
202
+
203
+ }
204
+
205
+ </script>
206
+
207
+ </head>
208
+
209
+ <body>
210
+
211
+ <form method="post" action="a.php" onsubmit="return condition()">
212
+
213
+ <table>
214
+
215
+ <tr>
216
+
217
+ <td>
218
+
219
+ 名前:<input type="text" name="name" id="name">
220
+
221
+ 内容:<textarea name="comment" cols="30" rows="3" id="comment"></textarea>
222
+
223
+ <input type="radio" name="bbs" id="r1" value="post" onChange="change(this)">投稿
224
+
225
+ <input type="radio" name="bbs" id="r2" value="update" onChange="change(this)">更新
226
+
227
+ <input type="radio" name="bbs" id="r3" value="delete" onChange="change(this)">削除
228
+
229
+ <input type="submit" value="投稿" id="send">
230
+
231
+ </td>
232
+
233
+ </tr>
234
+
235
+ </table>
236
+
237
+
238
+
239
+ <?php
240
+
241
+
242
+
243
+ $link = mysqli_connect($host, $user, $pass, $dbname) or die("NG");
244
+
245
+
246
+
247
+ mysqli_select_db($link, "xxx");
248
+
249
+
250
+
251
+ $result = mysqli_query($link, "SELECT * FROM xxx ORDER BY time DESC");
252
+
253
+
254
+
255
+ while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
256
+
257
+ ?>
258
+
259
+
260
+
261
+ <table>
262
+
263
+ <input type="checkbox" name="chkid[]" value="<?=$row['id'] ?>">
264
+
265
+ <tr>
266
+
267
+ <td>名前:
268
+
269
+ <?php echo $row['name'] ?>
270
+
271
+ </td>
272
+
273
+ </tr>
274
+
275
+ <tr>
276
+
277
+ <td>内容:
278
+
279
+ <?php echo $row['comment'] ?>
280
+
281
+ </td>
282
+
283
+ </tr>
284
+
285
+ </table>
286
+
287
+
288
+
289
+ <?php
290
+
291
+ }
292
+
293
+ mysqli_free_result($result);
294
+
295
+
296
+
297
+ mysqli_close($link);
298
+
299
+ ?>
300
+
301
+
302
+
303
+ </form>
304
+
305
+ </body>
306
+
307
+ </html>
308
+
309
+ ```