I have a registration page and I want to validate the e-mail address. I'm having an issue with line 14 in particular. (I used a combination of several tutorials to make this).


if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['email']))

$username = mysql_real_escape_string($_POST['username']); 
$email = mysql_real_escape_string($_POST['email']); 
$result=ereg("^[^@ ]+@[^@ ]+\.[^@ ]+$",$email,$trashed);
echo "Enter a valid E-mail Address";

$password = md5($_POST['password']); 

$sql = mysql_query("SELECT username FROM usersystem WHERE username = 'username'");

If (mysql_num_rows($sql) >0) 

die ("Username is already taken."); 
mysql_query("INSERT INTO usersystem (username, password, email, ipadd) VALUES ( '$username', '$password', '$email', '$ip')") or die (mysql_error()); header("Location: login1.php");


<html><form action="register.php" method="post" name="register">
Username: <input name="username" type="text" />
Password: <input type="password" name="password" />
Email: <input name="email" type="text" />
<input type="submit" value="Submit"/>

If I leave line 14 in the code, when an invalid e-mail address comes up, it redirects to a new page and the message is: Enter a valid E-mail Address
Fatal error: Call to undefined function displayform() in /home/.../register.php on line 14

If I remove it (because I am honestly not sure why it is necessary) it does not check for a valid format on the e-mail addresses.

Any ideas?

Member Avatar

this give you an error because you never defined a function called displayform... if you want to validate an email use filter_var($mailToBeValidated, FILTER_VALIDATE_EMAIL) ... For more info, http://php.net/manual/en/function.filter-var.php

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.