QuizToon Posted June 28, 2009 Share Posted June 28, 2009 Hi all, Is it possible to check an entry against a database before deciding how to process. EG I have a basic contact form, Name, email, message. What I would like to happen is when the user hits the submit button I want to check if the email address already exists in the database. If it doesnt I want to post the info to a new record, if it does i dont want to post anything to the database, in both instances I want to send the form to an email recipient. If it is possible to do this please can someone either tell me where I will find a good tutorial which covers it or what search terms should I be searching for. I have tried for ages and just dont get the right results when I try to google. Thanks in advance Quote Link to comment Share on other sites More sharing options...
Philip Posted June 28, 2009 Share Posted June 28, 2009 $result = mysql_query("SELECT `email` FROM `members` WHERE `email`='{$email}' LIMIT 1"); if($mysql_num_rows($result)>0) { // you already have this user in the database } else { // You don't and should put an INSERT query here. } Of course, thats just an example. Quote Link to comment Share on other sites More sharing options...
dzelenika Posted June 28, 2009 Share Posted June 28, 2009 You should do select to see if there's given email in table, if not go further. eg: "SELECT Count(*) FROM contacts WHERE email = " . $_REQUEST['email'] if this select returns > 0 then do INSERT ... Quote Link to comment Share on other sites More sharing options...
QuizToon Posted June 30, 2009 Author Share Posted June 30, 2009 Thanks for the replies, I will be off to give them a try and see if I cant get it to work. Thanks again 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.