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 Link to comment https://forums.phpfreaks.com/topic/163994-posting-to-mysql-and-sending-emal/ 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. Link to comment https://forums.phpfreaks.com/topic/163994-posting-to-mysql-and-sending-emal/#findComment-865110 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 ... Link to comment https://forums.phpfreaks.com/topic/163994-posting-to-mysql-and-sending-emal/#findComment-865112 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 Link to comment https://forums.phpfreaks.com/topic/163994-posting-to-mysql-and-sending-emal/#findComment-866648 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.