2013-03-09 2 views
-1

사용자가 작성한 텍스트를 게시판에 게시하고 데이터베이스에 저장하는 코멘트 시스템이있는 소셜 미디어 웹 사이트를 만들고 있는데 문제는 텍스트가 표시되지 않고 텍스트가 없다는 것입니다. 데이터베이스에 저장되어 있지만 텍스트 옆에있는 다른 필드는 누구든지 나를 도울 수 있도록 저장되어 있습니까 ???PHP mysql + comment system

프로필 .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" />&nbsp;&nbsp; <img src="image with highlight 2/images/new images/imageHover/homeHover.jpg" height="50" width="40" />&nbsp;&nbsp; <img src="image with highlight 2/images/new images/imageHover/homeHover.jpg" height="50" width="40" />&nbsp;&nbsp; <img src="image with highlight 2/images/new images/imageHover/homeHover.jpg" height="50" width="40" />&nbsp;&nbsp; <img src="image with highlight 2/images/new images/imageHover/homeHover.jpg" height="50" width="40" />&nbsp;&nbsp; <img src="image with highlight 2/images/new images/imageHover/homeHover.jpg" height="50" width="40" />&nbsp;&nbsp; <img src="image with highlight 2/images/new images/imageHover/homeHover.jpg" height="50" width="40" />&nbsp;&nbsp; <img src="image with highlight 2/images/new images/imageHover/homeHover.jpg" height="50" width="40" />&nbsp;&nbsp; </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>&nbsp;</p> 
<p>&nbsp;</p> 
<p>&nbsp;</p> 
<p>&nbsp;</p> 
<p>&nbsp;</p> 
<p>&nbsp;</p> 
<p>&nbsp;</p> 
<?php require_once('footer.php'); ?> 

</body> 
</html> 

<?php flush(); ?> 
+0

코드의 관련 부분 만 보여 주면 도움이 될 것입니다. 문제에 관해서는 다음과 같습니다 :'$ writenCom = (isset ($ _ POST [ 'post']));'는 '$ writenCom'과 부울. '$ writeenCom = mysql_real_escape_string ($ _ POST [ 'post']);'그러나 mysql_를 사용하지 말아라. *'- 대신'mysqli_ *'또는 PDO를 사용하십시오. – Quasdunk

+0

INSERT 쿼리에서 mysql_fetch_array()를 호출하고있다. 그럴 일은 없을거야. INSERT 질의는 true/false를 반환하므로'if ($ query) {// it worked ...}'를 할 것입니다. 당신은 당신의 의견을 도출하지 않으므로, 이것은 주사를 넓게 여는 것입니다. 최소한 $ _POST 쿼리 입력 모두에 대해 반드시 mysql_real_escape_string()을 호출해야합니다. –

+0

사용자 ID를 기반으로 사용자 데이터를 가져 오는 함수를 만듭니다. – samayo

답변

0

내가 코드의 여러 문제를 참조하십시오. 먼저 $writenCom = (isset($_POST['post']));$writenCom을 TRUE/FALSE로 설정하고 DB에 삽입하려는 값입니다. 둘째, mysql_fetch_arraySELECT 쿼리를 실행하는 경우에만 의미가 있습니다. 결과 세트를 가져 오는을 위해 또한, 당신은 항상 사용자로부터 오는 데이터를 탈출해야

+0

에 대한 새로운 내용 "mysqli 또는 PDO를 사용하는 것이 좋습니다. 더 이상 사용되지 않는 mysql이 아닙니다."는 질문과 전혀 관련이 없습니다. – bizzehdee

+0

@bizzehdee : "추가적으로"시작되는 것을 보지 못하셨습니까? 필자는 기존 코드의 문제점을 설명하고 변수를 이스케이프 처리하는 것에 대한 일반적인 참고 사항을 추가했습니다. – a1ex07

1

대신 mysql_fetch_array

if (mysql_affected_rows() > 0) { 
    echo "comment success"; 
} else { 
    echo "insert comment failed"; 
} 

mysql_fetch_arraymysql_affected_rows를 사용해야합니다 (이 mysql 쓸모없는 mysqli 또는 PDO를 사용하도록 권장)입니다 select 개의 검색어 중

또는, 당신은 단지이다

if ($query) { 
    echo "comment success"; 
} else { 
    echo "insert comment failed"; 
} 

그 외에, 당신은 mysqli 또는 PDO 중 하나 로의 전환을 고려해야합니다 삽입 문에 대한 실패하거나 성공을위한 TRUE 또는 FALSEmysql_query의 반환 값을 테스트하기 때문에 수 mysql_* 함수는 지금까지 사용되지 않습니다.