2013-05-02 62 views
0

我已爲我的圖庫做了評論部分,但並不確定爲什麼只能對其做出1條評論,那麼它不會允許我對該條目執行任何更多評論由於某種原因無法對插入作出多種評論

插入

public function insertComment() { 
    if(!get_magic_quotes_gpc()) { 
     $this -> sanitizeInput(); 
    }   
    extract($_POST); 

    $name = $_SESSION['userName']; 
    $comment = $_POST['comment']; 
    $productID = $_GET['id']; 

    echo $name; 
    echo $comment; 
    echo $productID; 


    $qry = "INSERT INTO comments VALUES (NULL, '$name', '$comment', '$productID')"; 

    $rs = $this -> db -> query($qry); 

    if($rs && $this -> db -> affected_rows > 0) { 
     $msg = 'comment record created. '; 
     } else { 
     echo 'Error inserting comment'; 
    } 
    return $msg;  
} 

Field Type Collation Attributes Null Default Extra Action 
    id int(11)   No None auto_increment       
    name varchar(150) latin1_swedish_ci  No None         
    comment varchar(150) latin1_swedish_ci  No None         
    productID int(11)   No None 
+3

永遠不要使用'extract()'。這是一個非常懶惰的代碼的標誌,並複製了很多內置於php中的非常愚蠢的東西。即:register_globals。你也容易受到[SQL注入攻擊](http://bobby-tables.com)的影響。 – 2013-05-02 21:09:45

+0

你在哪裏見過'extract'的東西?自從15年以來,這種技術被認爲是不安全的。請注意,黑客可以通過在帖子中添加字段來覆蓋腳本中的變量。不應該使用! – hek2mgl 2013-05-02 21:11:09

+0

也許productID上的唯一索引? – nicolas 2013-05-02 21:18:06

回答

0

也許這將工作

$qry = "INSERT INTO comments (name, comment, productID) VALUES ('$name', '$comment', '$productID')"; 

刪除null

相關問題