Jump to content

email validation within a function


wright67uk

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/234634-email-validation-within-a-function/
Share on other sites

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');
}
}
?>

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');
}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.