仮twitterのようなアプリで投稿機能を作成しております。
その中で、私のコードだと1(多分セッション)という数字の表示しかされません。
入力フォームの表示とそれをデータベースに保存したいです。
また、私のコードの中で改善した方が良い所などもご指摘頂けると幸いです。
現状ではadd_posts関数で記事の投稿、show_posts関数で投稿した記事を配列で表示きるように作成中です。
課題になるのでセキュリティなどは二の次で製作しております。
大変見にくいかもしれませんが、よろしくお願いします。
<posts table>
id
int(11) AI PK
retweet_user_id
int(11)
content
varchar(255)
picture
varchar(255)
datetime_posted
timestamp
datetime_edited
datetime
deleted
datetime
created
datetime
modified
datetime
session_start(); function add_post($picture,$content,$created){ $sql = "insert into posts (picture,content,created) values ($picture, '". mysql_real_escape_string($content). "',now())"; $result = mysql_query($sql); } $_SESSION['id'] = 1; if(isset($_SESSION['id'])){ echo "<b>". $_SESSION['id']."</b>"; unset($_SESSION['id']); } add_post($picture,$content); $_SESSION['id'] = "Your post has been added!"; header("Location:.php"); function show_posts($id){ $posts = array(); $sql = "select content , created ,picture from posts where id = '$userid' order by created desc"; $result = mysql_query($sql); while($data = mysql_fetch_object($result)){$posts[] = array('created' => $data->stamp, 'userid' => $userid, 'content' => $data->body); } return $posts; } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Posts</title> </head> <body> <form method='POST' action='posts.php'> <p>Your status:</p> <textarea name='content' rows='5' cols='40' wrap=VIRTUAL></textarea> <p>Image</p> <input type="file" name="picture"> <p><input type='submit' value='submit'/></p> </form> </body> </html> コード
回答1件
あなたの回答
tips
プレビュー