My sql statement didnt work

$update_status="INSERT INTO user_chat (chatroom_id,user_id,active)
VALUES ('$chatroomid','$id','1')
WHERE NOT EXISTS (
SELECT user_id FROM user_chat WHERE user_id ='$id' AND chatroom_id = '$chatroomid' AND active = '1'
)";

i have used php and mysql.

the user_id have link with user table am i doing it wrong or missiong somthing?

This is a Microsoft SQL Server forum, so folk here may not be familiar with the syntax for MySQL, but in MS SQL I would not use VALUES for this but rather SELECT as follows:

INSERT INTO user_chat (chatroom_id,user_id,active)
SELECT '$chatroomid','$id','1'
WHERE NOT EXISTS (
SELECT user_id FROM user_chat WHERE user_id ='$id' AND chatroom_id = '$chatroomid' AND active = '1' 
)