views:

36

answers:

2

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($cadd);

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

caution: extreme n00b.

alt text alt text

+1  A: 

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

Jage
i dont get it. please elaborate
amit
aid is unique which means you cannot add duplicate aid numbers to that table. If it is a foreign key in a one to many relationship then it should not be unique or a primary key. It should just be a reference id to the other table.
Arthur Thomas
A: 

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).

Itay Moav
pls look at the question. the screenshot is of table comments
amit
never the less, my answer was correct ;-)
Itay Moav