erme Posted February 10, 2010 Share Posted February 10, 2010 Hi, I've pulled a few bits of code I've found together to create the below form. I am trying to get it to check what's entered in the 'Name' field against a database field called 'dbName'. If the name enetered already exists it asks the user to confirm by pressing another <button>, else it just sends the emails. <?php if (isset($_POST['submit'])) { $Name = trim(stripslashes($_POST['Name'])); $clientTo="email@email.co.uk"; $message_enq=""; $message_enq.="Name: $Name \n"; mail($clientTo, $subject, $message.$message_enq.$messagefooter, $emailheaders); $query = "SELECT dbName FROM Tablename WHERE dbName='{$_POST['Name']}'"; $resource = mysql_query($query); if (empty($Name)) { print "<h1>Thank you. Email sent!</p>"; exit; } else { if (mysql_num_rows($resource) == 0){ } else { print "Are you sure you are not already listed?<br /><br />"; echo "<button type=\"submit\" name=\"submit\" id=\"submit\">No I'm Not Listed. Add Me</button>"; exit; } } } ?> <form id="contactBox" method="post" action="page.php"> <input type="text" id="Name" name="Name" value="<?=$Name;?>" /><br /> <button type="submit" name="submit" id="submit">Add Me</button> </form> Thanks for looking. Quote Link to comment Share on other sites More sharing options...
mapleleaf Posted February 10, 2010 Share Posted February 10, 2010 I would use $Name in your query but otherwise what is going wrong? Quote Link to comment Share on other sites More sharing options...
erme Posted February 10, 2010 Author Share Posted February 10, 2010 If nothing is entered the 'Email sent' message is displayed and email sent (correct) If a name is entered that isn't in database an email is sent (correct) but 'Email sent' message is not displayed. If a name is entered that is in database the 'Are you sure you are not already listed' message is displayed but email is sent (don't want this) and the button doesn't do anything. Quote Link to comment Share on other sites More sharing options...
mapleleaf Posted February 11, 2010 Share Posted February 11, 2010 This is being sent to anyone who submits: mail($clientTo, $subject, $message.$message_enq.$messagefooter, $emailheaders); You need to put it inside the condition like: if (empty($Name)) { mail($clientTo, $subject, $message.$message_enq.$messagefooter, $emailheaders); print "<h1>Thank you. Email sent!</p>"; exit; } else { if (mysql_num_rows($resource) == 0){ mail($clientTo, $subject, $message.$message_enq.$messagefooter, $emailheaders); } You also need to add an onclick to your button so it does something Quote Link to comment Share on other sites More sharing options...
erme Posted February 11, 2010 Author Share Posted February 11, 2010 How can i get the second submit button to send the form? 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.