I made this code:

INSERT into author(authorfirstname1, authorlastname1,authorfirstname2,  authorlastname2) 
    select '".addslashes($_POST['authorfirstname1'])."','".addslashes($_POST['authorlastname1'])."','".addslashes($_POST['authorfirstname2'])."','".addslashes($_POST['authorlastname2'])."'
  from author      
where not exists(select authorfirstname1, authorlastname1, authorfirstname2, authorlastname2 from author 
        where author.authorfirstname1='".addslashes($_POST['authorfirstname1'])."' 
            and author.authorlastname1='".addslashes($_POST['authorlastname1'])."' 
                and author.authorfirstname2='".addslashes($_POST['authorfirstname2'])."' 
                    and author.authorlastname2='".addslashes($_POST['authorlastname2'])."'

The point of this code should be that it checks, if a value allready exists in database and if it doesnt, then it enters it.
This '".addslashes($_POST['authorlastname2'])."' represents an input, but could easyly be replaced with '%myentereddata%'

My problem is that it doesnt do anything...doesnt even give error message, its success, but it doesnt enter data if data doesnt exist in db allready and not sure if it stops entering data if data exists.

So I would be thankful if someone could help me to solve the problem with this code or give another example how to do it differently, so that it would work.

Problem Solved
INSERT into author(authorfirstname1, authorlastname1,authorfirstname2, authorlastname2)
select 'one','two','three','four'
where not exists(select 1 from author
where author.authorfirstname1='one'
and author.authorlastname1='two'
and author.authorfirstname2='three'
and author.authorlastname2='four'

Grats to Daniel Vérité from stackoverflow.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.