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

質問編集履歴

1

コードの変数を編集しました。

2019/05/23 01:11

投稿

amaturePy
amaturePy

スコア131

title CHANGED
File without changes
body CHANGED
@@ -24,7 +24,7 @@
24
24
  include_once("functions.php");
25
25
 
26
26
  $userid = $_SESSION['userid'];
27
- $body = substr($_POST['body'],0,140);
27
+ $body = substr($_POST['content'],0,140);
28
28
 
29
29
  add_post($userid,$body);
30
30
  $_SESSION['message'] = "Your post has been added!";
@@ -38,7 +38,7 @@
38
38
  unset($_SESSION['message']);
39
39
  }
40
40
  ?>
41
- <form method='post' action='add.php'>
41
+ <form method='post' action='index.php'>
42
42
  <p>Your status:</p>
43
43
  <textarea name='body' rows='5' cols='40' wrap=VIRTUAL></textarea>
44
44
  <p><input type='submit' value='submit'/></p>
@@ -75,8 +75,8 @@
75
75
  function.php
76
76
  <?php
77
77
  function add_post($userid,$body){
78
- $sql = "insert into posts (user_id, body, stamp)
78
+ $sql = "insert into posts (content,created)
79
- values ($userid, '". mysql_real_escape_string($body). "',now())";
79
+ values ($content,now());
80
80
 
81
81
  $result = mysql_query($sql);
82
82
  }
@@ -84,15 +84,12 @@
84
84
  function show_posts($userid){
85
85
  $posts = array();
86
86
 
87
- $sql = "select body, stamp from posts
87
+ $sql = "select content,created from posts
88
- where user_id = '$userid' order by stamp desc";
88
+ where id = '$content' order by created desc";
89
89
  $result = mysql_query($sql);
90
90
 
91
91
  while($data = mysql_fetch_object($result)){
92
- $posts[] = array( 'stamp' => $data->stamp,
92
+ $posts[] = array( 'content' => $cntent);
93
- 'userid' => $userid,
94
- 'body' => $data->body
95
- );
96
93
  }
97
94
  return $posts;
98
95