wright67uk Posted April 25, 2011 Share Posted April 25, 2011 Hello i have a syntax issue in the code below, can anyone shed some light? <?php if(isset($_POST['submit'])) { $drop = mysql_real_escape_string($_POST['drop_1']); $tier_two = mysql_real_escape_string($_POST['Subtype']); echo "You selected "; echo $drop." & ".$tier_two; $Name = mysql_real_escape_string($_POST["Name"]); $Phone = mysql_real_escape_string($_POST["Phone"]); $Email = mysql_real_escape_string($_POST["Email"]); $Postcode = mysql_real_escape_string($_POST["Postcode"]); $Website = mysql_real_escape_string($_POST["Website"]); if($Name == '' || $Phone == '' || $Email == '' else if (!preg_match('/^[A-Za-z0-9\-.]+$/', $domain)|| $Postcode == '' || $Website == '') { die('<br> but you did not complete all of the required fields correctly, please try again'); } } the code works fine without the " else if (!preg_match('/^[A-Za-z0-9\-.]+$/', $domain) " . As well as checking for blank fields i'd like to check for the correct email format. Many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/234634-email-validation-within-a-function/ Share on other sites More sharing options...
gristoi Posted April 25, 2011 Share Posted April 25, 2011 you cant nest the else if within an IF statement like that, change it to an OR || Quote Link to comment https://forums.phpfreaks.com/topic/234634-email-validation-within-a-function/#findComment-1205780 Share on other sites More sharing options...
wright67uk Posted April 25, 2011 Author Share Posted April 25, 2011 thats what I orginally thought; </form> </p> <p> <?php if(isset($_POST['submit'])) { $drop = mysql_real_escape_string($_POST['drop_1']); $tier_two = mysql_real_escape_string($_POST['Subtype']); echo "You selected "; echo $drop." & ".$tier_two; $Name = mysql_real_escape_string($_POST["Name"]); $Phone = mysql_real_escape_string($_POST["Phone"]); $Email = mysql_real_escape_string($_POST["Email"]); $Postcode = mysql_real_escape_string($_POST["Postcode"]); $Website = mysql_real_escape_string($_POST["Website"]); if($Name == '' || $Phone == '' || $Email == '' or (!preg_match('/^[A-Za-z0-9\-.]+$/', $domain)|| $Postcode == '' || $Website == '') { die('<br> but you did not complete all of the required fields correctly, please try again'); } } echo "<br>"; echo $Name; echo "<br>"; echo $Website; $query = ("INSERT INTO business (`id`, `Name`, `Type`, `Subtype`, `Phone`, `Email`, `Postcode`, `WebAddress`) VALUES ('NULL', '$Name', '$drop', '$tier_two' , '$Phone', '$Email', '$Postcode', '$Website')"); mysql_query($query) or die ( "<br>Query: $query<br>Error: " .mysql_error()); ?> </body> </html> but then I get the error message; Parse error: syntax error, unexpected '{' on line 70 <?php if($Name == '' || $Phone == '' || $Email == '' or (!preg_match('/^[A-Za-z0-9\-.]+$/', $domain)|| $Postcode == '' || $Website == '') { //LINE 70 die('<br> but you did not complete all of the required fields correctly, please try again'); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/234634-email-validation-within-a-function/#findComment-1205782 Share on other sites More sharing options...
gristoi Posted April 25, 2011 Share Posted April 25, 2011 try ($Name == '' || $Phone == '' || $Email == '' || !preg_match('/^[A-Za-z0-9\-.]+$/', $domain) || Quote Link to comment https://forums.phpfreaks.com/topic/234634-email-validation-within-a-function/#findComment-1205784 Share on other sites More sharing options...
wright67uk Posted April 25, 2011 Author Share Posted April 25, 2011 I did try that, and I also tried the below code. Neither return any error messages, however neither submit to my database, the die message is displayed when the submit button is pressed no matter what is in the fields. (I've tried the form with my own email address) <?php if(isset($_POST['submit'])) { $drop = mysql_real_escape_string($_POST['drop_1']); $tier_two = mysql_real_escape_string($_POST['Subtype']); echo "You selected "; echo $drop." & ".$tier_two; $Name = mysql_real_escape_string($_POST["Name"]); $Phone = mysql_real_escape_string($_POST["Phone"]); $Email = mysql_real_escape_string($_POST["Email"]); $Postcode = mysql_real_escape_string($_POST["Postcode"]); $Website = mysql_real_escape_string($_POST["Website"]); if($Name == '' || $Phone == '' || $Email == '' or (!filter_var($email, FILTER_VALIDATE_EMAIL))|| $Postcode == '' || $Website == '') { die('<br> but you did not complete all of the required fields, please try again'); } } Quote Link to comment https://forums.phpfreaks.com/topic/234634-email-validation-within-a-function/#findComment-1205802 Share on other sites More sharing options...
gristoi Posted April 25, 2011 Share Posted April 25, 2011 your using $Email = mysql_real_escape_string($_POST["Email"]); but calling lowercase email filter_var($email, FILTER_VALIDATE_EMAIL) Quote Link to comment https://forums.phpfreaks.com/topic/234634-email-validation-within-a-function/#findComment-1205803 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.