开发者

mysql DB not adding rows with similar elements

开发者 https://www.devze.com 2022-12-14 18:18 出处:网络
i have created a DB with 3 columns: aid, qid and message. aid is a foreign key which will be commond with another table.

i have created a DB with 3 columns: aid, qid and message.

aid is a foreign key which will be commond with another table. comments is a varchar which stores user comments

its partially working. the problem is aid is not adding duplicate values. suppose i want to add comments related to specific aid. there are 18 aid's in all. and i want to filter the comments according to aid's. the table is not adding a duplicate aid.

this is the query I am using in php:

    $query = "UPDATE answers SET acount = acount + 1 WHERE aid = $vote";
    $result = mysql_query($query);
    $cadd = "INSERT INTO comments (aid, msg) VALUES ('$vote','$comment')";
    mysql_query($c开发者_高级运维add);

what am i doing wrong. i am attaching a screenshot of the DB structure.

caution: extreme n00b.

mysql DB not adding rows with similar elements

mysql DB not adding rows with similar elements


It looks like aid is your primary key, which should be unique.


Show table comments. I would guess the PK there is aid.
b.t.w your code is vulnerable to sql injection (unless this is only for the sake of debugging).

0

精彩评论

暂无评论...
验证码 换一张
取 消