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 Link to comment https://forums.phpfreaks.com/topic/14191-how-to-check-if-a-tuple-is-already-in-a-mysql-database-with-php/ 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. Link to comment https://forums.phpfreaks.com/topic/14191-how-to-check-if-a-tuple-is-already-in-a-mysql-database-with-php/#findComment-55643 Share on other sites More sharing options...
paolinaaaaaaa Posted July 13, 2006 Author Share Posted July 13, 2006 thanks :) Link to comment https://forums.phpfreaks.com/topic/14191-how-to-check-if-a-tuple-is-already-in-a-mysql-database-with-php/#findComment-57281 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.