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

質問編集履歴

1

改善

2016/09/09 02:22

投稿

a-_.
a-_.

スコア133

title CHANGED
File without changes
body CHANGED
@@ -11,4 +11,145 @@
11
11
 
12
12
  試しにformタグのaction属性にa.phpを入れて確認してみたんですが、正しく処理されなかったです
13
13
 
14
- 因みに調べていると「http://~.js」という書き方があるのを把握したんですが、この書き方はどういうリンクの貼り方なんでしょうか
14
+ 因みに調べていると「http://~.js」という書き方があるのを把握したんですが、この書き方はどういうリンクの貼り方なんでしょうか
15
+
16
+ 追記
17
+ 上がa.php
18
+ ```PHP
19
+ <?php
20
+ header("Content-Type: application/json; charset=UTF-8");
21
+
22
+ if ($_POST['bbs'] == "post") {
23
+ require ("XXX1.php");
24
+ $p_obj = new Post();
25
+ $p_obj -> name = $_POST['name'];
26
+ $p_obj -> comment = $_POST['comment'];
27
+ $p_obj -> post();
28
+ } elseif ($_POST['bbs'] == "update") {
29
+ require ("XXX2.php");
30
+ $u_obj = new Update();
31
+ $u_obj -> name = $_POST['name'];
32
+ $u_obj -> comment = $_POST['comment'];
33
+ $u_obj -> chk = $_POST['chk'];
34
+ $u_obj -> update();
35
+ } elseif ($_POST['bbs'] == "delete") {
36
+ require ("XXX3.php");
37
+ $d_obj = new Delete();
38
+ $d_obj -> chk = $_POST['chk'];
39
+ $d_obj -> delete();
40
+ }
41
+
42
+ require("XXX4.php");
43
+ $l_obj = new List_table;
44
+ $data = $l_obj -> list();
45
+ echo json_encode($data);
46
+ exit;
47
+ ?>
48
+ ```
49
+ 下がb.php
50
+ ```
51
+ <html>
52
+ <head>
53
+ <meta charset="utf-8">
54
+ <meta http-equiv="Content-Script-Type" content="text/javascript">
55
+ <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
56
+ <script>
57
+ $(function() {
58
+ $('input[name=bbs]').click(function(e) {
59
+ change($(this).prop('id'));
60
+ });
61
+ change($('input[name=bbs]:checked').prop('id'));
62
+ });
63
+ function condition() {
64
+ if ($('#r1').prop('checked')) {
65
+ with($('#name')) {
66
+ if (val().length >= 10) {
67
+ alert("ERROR");
68
+ return false;
69
+ }
70
+ if (val() === "") {
71
+ alert("ERROR");
72
+ return false;
73
+ }
74
+ }
75
+ with($('#comment')) {
76
+ if (val().length >= 300) {
77
+ alert("ERROR");
78
+ return false;
79
+ }
80
+ if (val() === "") {
81
+ alert("ERROR");
82
+ return false;
83
+ }
84
+ }
85
+ }
86
+ if($('#r2').prop('checked')||$('#r3').prop('checked')) {
87
+ if ($('[name="chkid[]"]:checked').length == 0) {
88
+ window.alert("ERROR");
89
+ return false;
90
+ }
91
+ }
92
+ return true;
93
+ }
94
+ function change(myid) {
95
+ var sendlist = {
96
+ "r1":{"text":"投稿",checkflg:true},
97
+ "r2":{"text":"更新",checkflg:false},
98
+ "r3":{"text":"削除",checkflg:false},
99
+ };
100
+ $('#send').val(sendlist[myid].text);
101
+ $('[name="chkid[]"]').prop('disabled',sendlist[myid].checkflg);
102
+ }
103
+ </script>
104
+ </head>
105
+ <body>
106
+ <form method="post" action="a.php" onsubmit="return condition()">
107
+ <table>
108
+ <tr>
109
+ <td>
110
+ 名前:<input type="text" name="name" id="name">
111
+ 内容:<textarea name="comment" cols="30" rows="3" id="comment"></textarea>
112
+ <input type="radio" name="bbs" id="r1" value="post" onChange="change(this)">投稿
113
+ <input type="radio" name="bbs" id="r2" value="update" onChange="change(this)">更新
114
+ <input type="radio" name="bbs" id="r3" value="delete" onChange="change(this)">削除
115
+ <input type="submit" value="投稿" id="send">
116
+ </td>
117
+ </tr>
118
+ </table>
119
+
120
+ <?php
121
+
122
+ $link = mysqli_connect($host, $user, $pass, $dbname) or die("NG");
123
+
124
+ mysqli_select_db($link, "xxx");
125
+
126
+ $result = mysqli_query($link, "SELECT * FROM xxx ORDER BY time DESC");
127
+
128
+ while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
129
+ ?>
130
+
131
+ <table>
132
+ <input type="checkbox" name="chkid[]" value="<?=$row['id'] ?>">
133
+ <tr>
134
+ <td>名前:
135
+ <?php echo $row['name'] ?>
136
+ </td>
137
+ </tr>
138
+ <tr>
139
+ <td>内容:
140
+ <?php echo $row['comment'] ?>
141
+ </td>
142
+ </tr>
143
+ </table>
144
+
145
+ <?php
146
+ }
147
+ mysqli_free_result($result);
148
+
149
+ mysqli_close($link);
150
+ ?>
151
+
152
+ </form>
153
+ </body>
154
+ </html>
155
+ ```