2011-08-15 112 views
0

我想從用戶那裏得到評論,但瀏覽器說致命錯誤:函數名稱必須是字符串。我的代碼;致命錯誤函數名稱必須是字符串

// <form name="form1" method="post" action="posting.php"> 
// <input name="comment" type="text" id="comment" style="width:254px; height:44px;"> 
// </form> 

<?php 

    $comment = $_POST('comment');//this was the line where problem occured 

    if(!empty($comment)) 
    { 
    mysql_query("INSERT INTO comment (comment) VALUES('".$comment."')"); 
    } 

    echo "$comment"; 

?> 

回答

1

當你想要方括號時,你在$_POST之後使用了圓括號。

10

使用括號進行數組解引用:[]。所以....

$comment = $_POST['comment']; 
1
$_POST['comment']; 

方括號,而不是括號。

1

大概

$_POST['comment'] 

,而不是( '評論')。順便說一句:除非你不在乎SQL注入/ XSS攻擊

+0

而不是$ comment = $ _POST ['comment']我會寫$ comment = mysql_real_escape_string($ _ POST ['評論'])。然後當你顯示它時,確保你可以把它包裝在htmlentities()方法中。可能這是不夠的,但總比沒有好 – mkk

0

Use $_POST['comment'] instead of $_POST('comment');

Use $_POST['comment'] instead of $_POST('comment');

相關問題