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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.