Welcome Guest, Not a member yet? Register   Sign In
Make table with two record unique

this is very simple.
this case call composite primary key. you can google for this.

create new table 
sUsername Primary Key char(8)
sProductID primary key int(11)
sDatetime timestamp current_timestamp

try to add entry directly from php myadmin
sUsername : tony
sProducID: 1

sUsername: tony
sProductID: 2

sUsername: joe
sProductID: 1

all above will successfull. and below will not allowed

sUsername: tony
sProductID: 1

this is what do you want, right?

in PHP you need to check this 
select * from tbl_user_product_relation where sUsername=? and sProductID=?
if num_rows() == 1 Insert
else echo 'duplicate'


Quote:hei.. what about my sID?

you dont need that. What you know about table is: every table must have id as primary key and auto_increment
Nooooo... that's totally wrong.
and if you pretend to not remove sID, you will have 3 composite primary key, and you will always have duplicate possibility,

sID sUsername sProductID
1 tony 1
2 tony 1
3 tony 1
100 tony 1

is different

Messages In This Thread
RE: Make table with two record unique - by plonknimbuzz - 12-16-2017, 10:58 PM

Theme © iAndrew 2016 - Forum software by © MyBB