我正在創建一個評論系統的社交媒體網站,其中用戶寫的文本將發佈在論壇上並存儲在數據庫中,但問題是沒有文本顯示,也沒有文本存儲在數據庫中,但文本旁邊的其他領域存儲,所以任何人都可以幫助我?php mysql +評論系統
輪廓.PHP
<?php
ob_start();
session_start();
require_once('for members/scripts/global.php');
if($_SESSION['login'] != 'true'){
header("location:index.php");
}
$user_id = $_SESSION['user_id'];
$send =(isset($_POST['send']));
$writenCom = (isset($_POST['post']));
if($send && $writenCom){
echo $writenCom;
$query = mysql_query("INSERT INTO comment(sender_id, text, comment_date)VALUES('$user_id', '$writenCom', now())")or die(mysql_error());
while($row = mysql_fetch_array($query)){
echo"comment success";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style/stylesheet.css"rel="stylesheet" type="text/css"/>
<title>
<?php print($_SESSION['first_name']); ?>
<?php print($_SESSION['last_name']); ?>'s profile</title>
<style type="text/css">
</style>
<link href="style/stylesheet.css" type="text/css"/>
</head>
<body>
<?php require_once('header.php'); ?>
<div class="container center">
<div class="postForm">
<form action="<?php echo($_SESSION['first_name']); ?>" method="post">
<textarea id="post" name="post" rows="5" cols="70"> </textarea>
<input type="submit" name="send" value="Post" style="background-color:#DCE5EE; float:right; border:1px solid #666; color:#666; height:73px; width:65px;" />
</form>
</div>
<div class="profilePost">Your Post will go here...
</div>
<!--for posting area -->
<div class="textProfileHeader"><?php echo($_SESSION['first_name']); ?>'s profile</div>
<!--end of posting -->
<div class="profileImage"><img src="image with highlight 2/images/new images/imageHover/homeHover.jpg" height="250" width="200" alt="<?php echo($_SESSION['first_name']); ?>'s profile" title="="<?php echo($_SESSION['first_name']);?>'s profile /></div>
<div class="profiletextContent">Some Content about this person profile...</div>
<div class="textProfileHeaderFriends"><?php echo($_SESSION['first_name']); ?>'s Friends</div>
<div class="profileImgFriends"> <img src="image with highlight 2/images/new images/imageHover/homeHover.jpg" height="50" width="40" /> <img src="image with highlight 2/images/new images/imageHover/homeHover.jpg" height="50" width="40" /> <img src="image with highlight 2/images/new images/imageHover/homeHover.jpg" height="50" width="40" /> <img src="image with highlight 2/images/new images/imageHover/homeHover.jpg" height="50" width="40" /> <img src="image with highlight 2/images/new images/imageHover/homeHover.jpg" height="50" width="40" /> <img src="image with highlight 2/images/new images/imageHover/homeHover.jpg" height="50" width="40" /> <img src="image with highlight 2/images/new images/imageHover/homeHover.jpg" height="50" width="40" /> <img src="image with highlight 2/images/new images/imageHover/homeHover.jpg" height="50" width="40" /> </div>
<!--
<form id="form" method="post" action="profile.php" enctype="multipart/form-data" target="iframe">
<input type="file" id="file" name="file" />
<input type="submit" name="submit" id="submit" value="Upload File" />
</form>
-->
<!--
<a href="#">edit profile</a><br />
<a href="#">account settings</a><br />
-->
<?php
//}else{
//header("Location: home.php");
?>
<!--
<a href="#">private message</a><br />
<a href="#">add as friend</a><br />
-->
<?php
//}
?>
</div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<?php require_once('footer.php'); ?>
</body>
</html>
<?php flush(); ?>
如果您只顯示代碼的相關部分,您可以更輕鬆地幫助您......關於您的問題:'$ writenCom =(isset($ _ POST ['post']));'指定一個布爾值爲'$ writenCom'。你不想知道它是否設置了,你想要它的值(並且你想先清理它):'''writenCom = mysql_real_escape_string($ _ POST ['post']);' - 但是請不要使用'mysql_ *' - 改用'mysqli_ *'或PDO。 – Quasdunk 2013-03-09 15:01:42
您正在'INSERT'查詢中調用'mysql_fetch_array()'。這將無法工作。 INSERT查詢返回true/false,所以你會'if($ query){//它工作...}'。你也不是逃避你的輸入,所以這是開放的注射。至少你必須在所有'$ _POST'查詢輸入中調用'mysql_real_escape_string()'。 – 2013-03-09 15:04:20
創建一個函數,根據用戶ID獲取用戶數據 – samayo 2013-03-09 15:05:38