benjaminmorgan Posted October 19, 2011 Report Share Posted October 19, 2011 I have a form and whenever I am entering a invalid email it still goes through. I have the form set where if it isn't valid it will pop up an error... BUT when I put in the php section it is this. if (isset($_REQUEST['Submit'])) { $FName=$_POST['fullname']; $CName=$_POST['comname']; $Cwebsite=$_POST['cwebsite']; $Email=$_POST['blemail']; $comabout=$_POST['comabout']; $prequirements=$_POST['prequirements']; $pagenumber=$_POST['pagenum']; if( $_POST['fullname']!="" || $_POST['blemail']!="" || $_POST['comabout']!="" || $_POST['prequirements']!="" || $_POST['pagenum']!="" || $_POST['blemail']==preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['blemail'])) { $query="INSERT INTO quote (full_name, company_name, website, email, company_about, project_requirements, page_numbers)VALUES('".$FName."', '".$CName."', '".$Cwebsite."', '".$Email."', '".$comabout."', '".$prequirements."', '".$pagenumber."')"; mysql_query($query) or die("Error updating database.". mysql_error()); } } ************************************************************************** table name is quote and it is inserting fine. I just want to stop it if it does not meet any of the following. I can just submit the form blank (except for the pages because it is a dropdown option with one preselected. ) I want to stop the form if a required field is blank OR the email doesn't match the reg ex ************************************************************************** Quote Link to comment Share on other sites More sharing options...
benjaminmorgan Posted October 19, 2011 Author Report Share Posted October 19, 2011 anyone know? Quote Link to comment Share on other sites More sharing options...
benjaminmorgan Posted October 20, 2011 Author Report Share Posted October 20, 2011 still submits even if changed to && Quote Link to comment Share on other sites More sharing options...
benjaminmorgan Posted October 20, 2011 Author Report Share Posted October 20, 2011 the only time it won't submit if all fields are blank. other than that if u just type one thing in a box it will submit. Quote Link to comment Share on other sites More sharing options...
Wickham Posted October 20, 2011 Report Share Posted October 20, 2011 (edited) The way you have it, the code checks if a field is NOT empty, try reversing it so it checks if any field IS empty:- // Code to check for empty input boxes (edit to suit your form) if (empty($email) || empty($name) || empty($subject) || empty($component) || empty($size)) { echo "Please complete all boxes"; } else ......... Separate the email check into a separate if statement. It's often best to download a form script that has many security features. Edited October 20, 2011 by Wickham Quote Link to comment Share on other sites More sharing options...
benjaminmorgan Posted October 20, 2011 Author Report Share Posted October 20, 2011 I did that and it is still submitting to database. Quote Link to comment Share on other sites More sharing options...
benjaminmorgan Posted October 20, 2011 Author Report Share Posted October 20, 2011 and where can i download a form script? Quote Link to comment Share on other sites More sharing options...
benjaminmorgan Posted October 20, 2011 Author Report Share Posted October 20, 2011 http://pastebin.com/SpDarS8J here is my code Quote Link to comment Share on other sites More sharing options...
falkencreative Posted October 21, 2011 Report Share Posted October 21, 2011 So when you try to submit the form now, what are you experiencing? Errors? It doesn't do what you expect? The code itself looks good, as far as I can tell... why the "global" references on lines 12-18? Quote Link to comment Share on other sites More sharing options...
benjaminmorgan Posted October 21, 2011 Author Report Share Posted October 21, 2011 i was just trying to fix it. I can submit it to the database even if it is blank or not valid. I don't want that. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted October 21, 2011 Report Share Posted October 21, 2011 Are you sure that's the exact code? You're missing closing brackets "}" for the two if statements at the top of the page. I can't run your code without errors, and it works as far as I can tell when those if statements are closed properly. Quote Link to comment Share on other sites More sharing options...
benjaminmorgan Posted October 22, 2011 Author Report Share Posted October 22, 2011 http://pastebin.com/SpDarS8J is my exact code. I don't see any non closed if statements. there is an if within an if though. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted October 22, 2011 Report Share Posted October 22, 2011 http://pastebin.com/SpDarS8J is my exact code. I don't see any non closed if statements. there is an if within an if though. Can you point out which two lines have the closing "}" for the two if statements? You need if ($_POST) { ... your code... if( $FName!="" && $Email!="" && $comabout!="" && $prequirements!="" && $Email==preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $Email) ) { ... more code } // closing bracket } // closing bracket Quote Link to comment Share on other sites More sharing options...
benjaminmorgan Posted October 22, 2011 Author Report Share Posted October 22, 2011 I had them closed in my code, is my new code with them closed (26 and 27) and i took Email == the preg match off and just left preg match and it seems to be working it is just sending duplicates of each form now. i also commented out the global variables. Quote Link to comment Share on other sites More sharing options...
benjaminmorgan Posted October 22, 2011 Author Report Share Posted October 22, 2011 Thanks for everyones help. Learning is hard but I will get it eventually. Like Stefan said just jump in and start learning 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.
Note: Your post will require moderator approval before it will be visible.