Forum Thread
  Posts  
[PHP] Checking Email Address (Forums : Coding & Scripting : [PHP] Checking Email Address) Locked
Thread Options 1 2
May 28 2003 Anchor
if (!ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $email))

Thats the code to check to see if its a valid email address, someone I need to integrate it into the code below, which is no easy task :S HELP!

<?

if ($username  == "" || $password == "" || $email == "" || $password != $password2)

{echo "Error - You missed something out, press back and try again";}

else

{$exists = false;
$usercheck = mysql_query("SELECT username,email FROM unz_users WHERE username = '$username'");
while($check = mysql_fetch_object($usercheck))

if($username == $check->username || $email == $check->email)
$exists = true;

if($exists == true)
{echo "Error - Username or Email address already exists";}

else

{mysql_query("INSERT INTO `unz_users` ( `uid` , `username` , `password`, `email`, `status`, `regdate`, `ip`, `host`) VALUES ('', '$username', '$password',  '$email', 'member', '$regdate', '$ip', '$host')");
echo &quot;$username</br>$password</br>$regdate</br>$email</br>$ip</br>$host </br>User added&quot;;}}

?&gt;

--

Why wont it save me?

INtense!
INtense! End Boss
May 28 2003 Anchor

Simple as this:

&lt;?

if ($username  == &quot;&quot; || $password == &quot;&quot; || $email == &quot;&quot; || $password != $password2)

{echo &quot;Error - You missed something out, press back and try again&quot;;}

else

{$exists = false;
$usercheck = mysql_query(&quot;SELECT username,email FROM unz_users WHERE username = &#039;$username&#039;&quot;);
while($check = mysql_fetch_object($usercheck))

if($username == $check-&gt;username || $email == $check-&gt;email)
$exists = true;

if($exists == true)
{echo &quot;Error - Username or Email address already exists&quot;;}
else if(!ereg(&#039;^[-!#$%&&#039;*+\./0-9=?A-Z^_`a-z{|}~]+&#039;.&#039;@&#039;.&#039;[-!#$%&&#039;*+\/0-9=?A-Z^_`a-z{|}~]+.&#039;.&#039;[-!#$%&&#039;*+\./0-9=?A-Z^_`a-z{|}~]+$&#039;, $email))
{echo &quot;Error - Please enter a valid email address i.e. me@mydomain.com&quot;;}
else

{mysql_query(&quot;INSERT INTO `unz_users` ( `uid` , `username` , `password`, `email`, `status`, `regdate`, `ip`, `host`) VALUES (&#039;&#039;, &#039;$username&#039;, &#039;$password&#039;,  &#039;$email&#039;, &#039;member&#039;, &#039;$regdate&#039;, &#039;$ip&#039;, &#039;$host&#039;)&quot;);
echo &quot;$username</br>$password</br>$regdate</br>$email</br>$ip</br>$host </br>User added&quot;;}}

?&gt;

--

Scott Reismanis
DBolical | @scottreismanis

INtense!
INtense! End Boss
May 28 2003 Anchor

Just need that one else if statement in there thats all

--

Scott Reismanis
DBolical | @scottreismanis

May 28 2003 Anchor

Parse error: parse error, unexpected '.' in /home/virtual/site101/fst/var/www/v2/pages/signup/signing_up.php on line 18

--

Why wont it save me?

jacksonj04
jacksonj04 Over 9000
May 28 2003 Anchor

INtense! can code samples have line numbers please?

you need to comment out any ' which is not part of a '.' arrangement, I think.

--

Barcode Imagejacksonj04 the generally helpful one
Lost, confused or just need a virtual cuddle? PM me.
Need urgent help from staff? PM us all.

May 29 2003 Anchor

Noticed, got it fixed, will posted updated code when I get back from work :(

--

Why wont it save me?

May 29 2003 Anchor

You realize that your "Username or Email already exists" message is flawed, right? You're not selecting on email = '$email', so the only time the "or Email" would apply is when the username is a duplicate, which is already tested. If you really want to make sure that the same email doesn't get used more than once, check username and email with separate queries.

Also, I have to admit that I dislike your style. Indenting bracketed code makes it much, much easier to read. Perhaps you're trying for obfuscation?

--

Give me ambiguity or give me... something else.

Dominant Species scope.creep User Posted Image

May 29 2003 Anchor

If you'd have read my above post you'd realise thats old code.

&lt;?

if (!$username || !$password || !$email || $password!=$password2)

{echo &quot;Error - You missed something out, press back and try again&quot;;}

else

{$exists = false;
$usercheck = mysql_query(&quot;SELECT username,email FROM unz_users WHERE username = &#039;$username&#039;&quot;);
while($check = mysql_fetch_object($usercheck))

if($username == $check-&gt;username || $email == $check-&gt;email)
$exists = true;

if($exists == true)
{echo &quot;Error - Username or Email address already exists&quot;;}
else if(!eregi(&quot;^([a-z0-9]+)([._-]([a-z0-9]+))*[@]([a-z0-9]+)([._-]([a-z0-9]+))*[.]([a-z0-9]){2}([a-z0-9])?$&quot;, $email))
{echo &quot;Error - Please enter a valid email address i.e. me@mydomain.com&quot;;}
else

{mysql_query(&quot;INSERT INTO `unz_users` ( `uid` , `username` , `password`, `email`, `status`, `regdate`, `ip`, `host`) VALUES (&#039;&#039;, &#039;$username&#039;, &#039;$password&#039;,  &#039;$email&#039;, &#039;member&#039;, &#039;$regdate&#039;, &#039;$ip&#039;, &#039;$host&#039;)&quot;);
echo &quot;Success - You are now a registered member of Wuggawoo.co.uk.&quot;;
setcookie (&quot;username&quot;, &quot;$username&quot;, time()+60*60*24*30,&#039;/&#039;,&#039;.wuggawoo.co.uk&#039;, 0);
setcookie (&quot;password&quot;, &quot;$password&quot;, time()+60*60*24*30,&#039;/&#039;,&#039;.wuggawoo.co.uk&#039;, 0);}}

?&gt;

Also my bracketing is fine, its my style and to me it makes more sense.

--

Why wont it save me?

May 30 2003 Anchor

I did read your previous post. Perhaps I didn't explain what I meant very well.

If you want to make sure that neither the username nor the email has been used before, do something like this:

&lt;?

if ( !$username || !$password || !$email || ($password != $password2) )
{
echo &quot;Error - You left something out, press back and try again&quot;;
}
else if ( !eregi(&quot;^([a-z0-9]+)([._-]([a-z0-9]+))*[@]([a-z0-9]+)([._-]([a-z0-9]+))*[.]([a-z0-9]){2}([a-z0-9])?$&quot;, $email) )
{
echo &quot;Error - Please enter a valid email address i.e. me@mydomain.com&quot;;
}
else if ( mysql_fetch_row(mysql_query( &quot;select username from unz_users where username = &#039;$username&#039;&quot; )) )
{
echo &quot;Error - Username already exists&quot;;
}
else if ( mysql_fetch_row(mysql_query( &quot;select email from unz_users where email = &#039;$email&#039;&quot; )) )
{
echo &quot;Error - Email already exists&quot;;
}
else if ( mysql_query(&quot;insert into unz_users (uid, username, password, email, status, regdate, ip, host) values (&#039;&#039;, &#039;$username&#039;, &#039;$password&#039;,  &#039;$email&#039;, &#039;member&#039;, &#039;$regdate&#039;, &#039;$ip&#039;, &#039;$host&#039;)&quot;) )
{
echo &quot;Success - You are now a registered member of wuggawoo.co.uk&quot;;
setcookie( &quot;username&quot;, &quot;$username&quot;, time()+60*60*24*30, &#039;/&#039;, &#039;.wuggawoo.co.uk&#039;, 0 );
setcookie( &quot;password&quot;, &quot;$password&quot;, time()+60*60*24*30, &#039;/&#039;, &#039;.wuggawoo.co.uk&#039;, 0 );
}
else
{
echo &quot;Error - There was a database error when attempting to save your information.  Please try again.&quot;;
}

?&gt;

As for your style, I merely said that I dislike it. It's my preference to indent.

[edit]
Well, the code tags don't handle indented code very well, so perhaps it's not really your style that I'm seeing.
[/edit]

- Edited By scope.creep On Fri 30th, May 2003 @ 4:26:03pm

[edit]
I'm not sure about those '$username', etc., things in the SQL. I'd have to test them out to be sure. I'd probably use the extra keystrokes to make it '".$username."', etc.
[/edit]

- Edited By scope.creep On Fri 30th, May 2003 @ 5:21:54pm

--

Give me ambiguity or give me... something else.

Dominant Species scope.creep User Posted Image

May 30 2003 Anchor

My defence for my identing is because I get thje same responce wherever I post it O_o

Your code doesnt work aswell, Error - You left something out, press back and try again no matter what.

--

Why wont it save me?

May 30 2003 Anchor

*shrug* I don't see how, since I cut/pasted your code, then added () for clarity.

[edit]
Why don't you echo those variables to see what they contain?
[/edit]

- Edited By scope.creep On Fri 30th, May 2003 @ 5:33:01pm

--

Give me ambiguity or give me... something else.

Dominant Species scope.creep User Posted Image

May 30 2003 Anchor

Bizarely everythings being sent to the page correctly and I even posted my if statement at the very top to see if it would work and it still wont, really odd O_o

Ok put my old version back and Im getting the same error so IM assuming its server side at the moment and will retry tomorow.

- Edited By azz0r On Fri 30th, May 2003 @ 11:43:19pm

--

Why wont it save me?

May 30 2003 Anchor

Ok the problem was me being logged in, hence username and password were already set, put a check on the signup page so its fixed now :D

Right, now all I have todo is
Username is minimum of 8 characters and contains no obscure characters
Password is minimum of 5 characters and contains no obscure characters
Error message saying that the passwords arent the same
Confirmation email sent to user...eek!

--

Why wont it save me?

jacksonj04
jacksonj04 Over 9000
May 30 2003 Anchor

simple:

eregi can sort obscure characters.
If ($password != $password2) sorts the password checking
mail (); is very simple, check in your book of words.

--

Barcode Imagejacksonj04 the generally helpful one
Lost, confused or just need a virtual cuddle? PM me.
Need urgent help from staff? PM us all.

May 30 2003 Anchor

Wrong password check (meant length)

&lt;?

if (!$username || !$password || !$email || $password!=$password2)
{echo &quot;Error - You missed something out, press back and try again&quot;;}



else if (!eregi(&quot;^([a-z0-9]+)([._-]([a-z0-9]+))*[@]([a-z0-9]+)([._-]([a-z0-9]+))*[.]([a-z0-9]){2}([a-z0-9])?$&quot;, $email))
{echo &quot;Error - Please enter a valid email address i.e. me@mydomain.com&quot;;}



else if (mysql_fetch_row(mysql_query(&quot;SELECT username FROM unz_users WHERE username = &#039;$username&#039;&quot; )))
{echo &quot;Error - Username already exists&quot;;}



else if (mysql_fetch_row(mysql_query(&quot;SELECT email FROM unz_users WHERE email = &#039;$email&#039;&quot;)))
{echo &quot;Error - Email already exists&quot;;}



else if ((strlen($username &lt; 6)))
{echo &quot;Error - Username must be 6+ characters long&quot;;}



else if(!ereg(&quot;^[[:alpha:]]{4,6}$&quot;, $username))
{echo &quot;Error - Weird characters in username; are you trying to harm me?&quot;;}



else if (mysql_query(&quot;INSERT into unz_users (uid, username, password, email, status, regdate, ip, host) VALUE (&#039;&#039;, &#039;$username&#039;, &#039;$password&#039;,  &#039;$email&#039;, &#039;member&#039;, &#039;$regdate&#039;, &#039;$ip&#039;, &#039;$host&#039;)&quot;))
{echo &quot;Success - You are now a registered member of wuggawoo.co.uk&quot;;
setcookie(&quot;username&quot;, &quot;$username&quot;, time()+60*60*24*30, &#039;/&#039;, &#039;.wuggawoo.co.uk&#039;, 0);
setcookie(&quot;password&quot;, &quot;$password&quot;, time()+60*60*24*30, &#039;/&#039;, &#039;.wuggawoo.co.uk&#039;, 0);}


{echo &quot;Error - There was a database error when attempting to save your information.  Please try again.&quot;;}

?&gt; 

I thought that might work, guess not :S

--

Why wont it save me?

May 30 2003 Anchor

azz0r wrote:

else if ((strlen($username &lt; 6)))
{echo &quot;Error - Username must be 6+ characters long&quot;;}

That's the problem. Try this:

else if ( strlen($username) &lt; 6 )
{
echo &quot;Error - Username must be 6+ characters long&quot;;
}

OR

else if ( (strlen($username) &lt; 6) || (strlen($username) &gt; 30) ) // field length in mysql
{
echo &quot;Error - Username must be 6-30 characters long&quot;;
}

--

Give me ambiguity or give me... something else.

Dominant Species scope.creep User Posted Image

May 31 2003 Anchor

Nope, I still just get 'Error - You missed something out, press back and try againError - There was a database error when attempting to save your information. Please try again' No matter what :(

--

Why wont it save me?

jacksonj04
jacksonj04 Over 9000
May 31 2003 Anchor

go easy on the brackets man! I missed out all the length stuff, sorry :/

As for your error, i dunno. I'll let you know if I find anything.

--

Barcode Imagejacksonj04 the generally helpful one
Lost, confused or just need a virtual cuddle? PM me.
Need urgent help from staff? PM us all.

May 31 2003 Anchor

OMG I DID IT AGAIN! LEFT MYSELF LOGGED IN.

- Edited By azz0r On Sat 31st, May 2003 @ 3:33:03pm

--

Why wont it save me?

May 31 2003 Anchor
&lt;?

if (!$username || !$password || !$email || $password!=$password2)
{echo &quot;Error - You missed something out, press back and try again&quot;;}



else if (!eregi(&quot;^([a-z0-9]+)([._-]([a-z0-9]+))*[@]([a-z0-9]+)([._-]([a-z0-9]+))*[.]([a-z0-9]){2}([a-z0-9])?$&quot;, $email))
{echo &quot;Error - Please enter a valid email address i.e. me@mydomain.com&quot;;}



else if (mysql_fetch_row(mysql_query(&quot;SELECT username FROM unz_users WHERE username = &#039;$username&#039;&quot; )))
{echo &quot;Error - Username already exists&quot;;}



else if (mysql_fetch_row(mysql_query(&quot;SELECT email FROM unz_users WHERE email = &#039;$email&#039;&quot;)))
{echo &quot;Error - Email already exists&quot;;}



else if (strlen($username) &lt; 6 )
{echo &quot;Error - Username must be 6+ characters long&quot;;}



else if(!ereg(&quot;^[[:alpha:]]{4,6}$&quot;, $username))
{echo &quot;Error - Weird characters in username; are you trying to harm me?&quot;;}



else if (mysql_query(&quot;INSERT into unz_users (uid, username, password, email, status, regdate, ip, host) VALUE (&#039;&#039;, &#039;$username&#039;, &#039;$password&#039;,  &#039;$email&#039;, &#039;member&#039;, &#039;$regdate&#039;, &#039;$ip&#039;, &#039;$host&#039;)&quot;))
{echo &quot;Success - You are now a registered member of wuggawoo.co.uk&quot;;
setcookie(&quot;username&quot;, &quot;$username&quot;, time()+60*60*24*30, &#039;/&#039;, &#039;.wuggawoo.co.uk&#039;, 0);
setcookie(&quot;password&quot;, &quot;$password&quot;, time()+60*60*24*30, &#039;/&#039;, &#039;.wuggawoo.co.uk&#039;, 0);}

else

{echo &quot;Error - There was a database error when attempting to save your information.  Please try again.&quot;;}

?&gt;

If you put the right details in it still says error, cant figure out whyyyyy

- Edited By azz0r On Sat 31st, May 2003 @ 4:53:50pm

--

Why wont it save me?

jacksonj04
jacksonj04 Over 9000
May 31 2003 Anchor

you're STILL logged in?

--

Barcode Imagejacksonj04 the generally helpful one
Lost, confused or just need a virtual cuddle? PM me.
Need urgent help from staff? PM us all.

Jun 1 2003 Anchor

I was yes, I didnt upload the signup.php page that checks to see if the cookie username is null :P

Anyway, it still echos Error - There was a database error when attempting to save your information. Please try again at the end of every error and never does success.

--

Why wont it save me?

jacksonj04
jacksonj04 Over 9000
Jun 1 2003 Anchor

your query.

mysql_query("INSERT into unz_users (uid, username, password, email, status, regdate, ip, host) VALUE ('', '$username', '$password', '$email', 'member', '$regdate', '$ip', '$host')")

should be

mysql_query("INSERT into unz_users (uid, username, password, email, status, regdate, ip, host) VALUES ('', '$username', '$password', '$email', 'member', '$regdate', '$ip', '$host')")

notice the VALUES not VALUE

--

Barcode Imagejacksonj04 the generally helpful one
Lost, confused or just need a virtual cuddle? PM me.
Need urgent help from staff? PM us all.

Jun 1 2003 Anchor

Ill try it to see if it fixes it, but its not echoing sucess - bla bla...

--

Why wont it save me?

jacksonj04
jacksonj04 Over 9000
Jun 1 2003 Anchor

um... um... is anything being added into your database at all? If not then you've got a duff query.

--

Barcode Imagejacksonj04 the generally helpful one
Lost, confused or just need a virtual cuddle? PM me.
Need urgent help from staff? PM us all.

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.