paolinaaaaaaa Posted July 10, 2006 Share Posted July 10, 2006 Probably a really stupid question but I am a total beginner ???...so here is the scenario:I have a html form in which people can insert a series of values.On pressing submit these values should be used to insert a tuple in a mysql database using php.However the values could already be in the database.I therefore need to check that beforehand.In short I need to do:IF (tuple already in db)return tuple primary keyELSEinsert tuple in dbreturn tuple primary keyhow could I do this?I have tried doing a select and seeing if it returns false but either I get a value (if the tuple is in the db) or I get an error (if the tuple is not in the db) and my script doesn't reach the end.Thank you very much,Paolina Quote Link to comment Share on other sites More sharing options...
fenway Posted July 10, 2006 Share Posted July 10, 2006 There are a few ways you can do this. However, no select query should ever return an error, just an empty result set, a boundary condition that you can easily check. Anyway, you could always do an INSERT IGNORE, provided you have an appropriate unique key across the relevant column; alternatively, you could do the select, and if no result, then insert, and pull back the last_insert_id. Quote Link to comment Share on other sites More sharing options...
paolinaaaaaaa Posted July 13, 2006 Author Share Posted July 13, 2006 thanks :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.