現在twitterの擬似版を作成しております。
しかし早くも投稿機能で躓いてしまい。
ブラウザからコードを展開することもできなくなってしまいました。
私のコードでなおしたよい所などご教授いただきたいです。
かなり危うい所はあると思うのですが、何卒よろしくお願いします。
session_start(); include_once('header.php'); include_once('functions.php'); $_SESSION['userid'] = 1; ?> <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Post</title> </head> <body> <?php session_start(); include_once("header.php"); include_once("functions.php"); $userid = $_SESSION['userid']; $body = substr($_POST['content'],0,140); add_post($userid,$body); $_SESSION['message'] = "Your post has been added!"; header("Location:index.php"); ?> <?php if (isset($_SESSION['message'])){ echo "<b>". $_SESSION['message']."</b>"; unset($_SESSION['message']); } ?> <form method='post' action='index.php'> <p>Your status:</p> <textarea name='body' rows='5' cols='40' wrap=VIRTUAL></textarea> <p><input type='submit' value='submit'/></p> </form> <?php $posts = show_posts($_SESSION['userid']); if (count($posts)){ ?> <table border='1' cellspacing='0' cellpadding='5' width='500'> <?php foreach ($posts as $key => $list){ echo "<tr valign='top'>\n"; echo "<td>".$list['userid'] ."</td>\n"; echo "<td>".$list['body'] ."<br/>\n"; echo "<small>".$list['stamp'] ."</small></td>\n"; echo "</tr>\n"; } ?> </table> <?php}else{?> <p><b>You haven't posted anything yet!</b></p> <?php}?> </body> </html> コード
コード
function.php <?php function add_post($userid,$body){ $sql = "insert into posts (content,created) values ($content,now()); $result = mysql_query($sql); } function show_posts($userid){ $posts = array(); $sql = "select content,created from posts where id = '$content' order by created desc"; $result = mysql_query($sql); while($data = mysql_fetch_object($result)){ $posts[] = array( 'content' => $cntent); } return $posts; } ?> コード
<header.php> <?php $SERVER = 'localhost'; $USER = 'root'; $PASS = 'root'; $DATABASE = 'microblog'; if (!($mylink = mysql_connect( 'localhost', 'root', 'root'))){ echo "<h3>Sorry, could not connect to database.</h3><br/> Please contact your system's admin for more help\n"; exit; } mysql_select_db('microblog'); ?> コード
<DB> CREATE TABLE `posts` ( `id` int(11) NOT NULL, `retweet_user_id` int(11) DEFAULT NULL, `content` varchar(255) NOT NULL, `picture` varchar(255) DEFAULT NULL, `datetime_posted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `datetime_edited` datetime NOT NULL, `deleted` datetime NOT NULL, `created` datetime NOT NULL, `modified` datetime NOT NULL, `user_id` int(11) NOT NULL, `body` varchar(255) NOT NULL, `stamp` datetime NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; コード
回答1件
あなたの回答
tips
プレビュー