Hello all!
Below I have a simple script that takes an email address from a user and stores it in a database. I have a regex validator in there, but it always returns false. any ideas why?
here is the code..
<?php
# this function will validate the email
function checkEmail($EMAIL)
{
if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $EMAIL))
{
return false;
}
}
# this is processed when the form is submitted
# back on to this page (POST METHOD)
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
# check the email is valid
if(checkEmail($EMAIL) == FALSE)
{
echo "E-mail entered is not valid.";
}
else
{
# escape data and set variables
$EMAIL = addslashes($_POST["EMAIL"]);
# setup SQL statement
$sql = " INSERT INTO elcartonazoemail ";
$sql .= " (email) VALUES ";
$sql .= " ('$EMAIL') ";
#execute SQL statement
$result = mysql_query($sql, $cid);
# check for error
if (mysql_error()) { print "Database ERROR: " . mysql_error(); }
print "<h3>email added</h3>";
}
}
?>
<form name="fa" action="index2.php" method="POST">
<table>
<tr><td><b>EMAIL: </b> </td><td><input type="text" name="EMAIL" size=30></td></tr>
<tr><th colspan=2><p><input type="submit" value="Add Record"></p></th></tr>
</table>