Welcome Guest ( Log In | Register)



2 Pages V   1 2 >  
Reply to this topicStart new topic
> Gahhh This Isn't Going Well Please Help!, It's a forgot password form in php!
chappill
post May 26 2008, 05:55 PM
Post #1


Member [Level 2]
*****

Group: [HOSTED]
Posts: 88
Joined: 21-April 08
From: Errm...this maps dodgey...i think im in the desert...
Member No.: 61,127



CODE
<?
// database connection details stored here
include "database.php";
?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>Thanks!</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<?
$email=mysql_real_escape_string($email);
$status = "OK";
$msg="";
//error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);
if (!stristr($email,"@") OR !stristr($email,".")) {
$msg="Your email address is not correct<BR>";
$status= "NOTOK";}
echo "<br><br>";
if($status=="OK"){ $query="SELECT * FROM users WHERE password = '$email'";
$st=mysql_query($query);
$recs=mysql_num_rows($st);
$row=mysql_fetch_object($st);
$em=$row->email;// email is stored to a variable
if ($recs == 0) { echo

That's a snippet of code from my forgot password form on my site...I don't know why it doesn't work. Here's a few links you may need to help:
http://chappill.trap17.com/test/test/login.php
http://chappill.trap17.com/test/test/register.php
http://chappill.trap17.com/test/test/forgot.php

Login is the login page, register is the register page and forgot is the forgotten password page, I hope you can help!
The problem is when you click submit on the forgotten password page it takes you off to the next page (like it should) but the next page displays
QUOTE
Your email address is not correct
Even though I know It's right... so there must be something wrong wth the way the script gets the information out of the MySQL database, heres the full code: http://www.chappill.trap17.com/test/test/lookhere.txt

This post has been edited by chappill: May 26 2008, 07:08 PM
Go to the top of the page
 
+Quote Post
rvalkass
post May 26 2008, 07:18 PM
Post #2


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,156
Joined: 28-May 05
From: Devon, England
Member No.: 7,593
Spam Patrol



The problem lies with the way you check for the pattern of an email address:
CODE
if (!stristr($email,"@") OR !stristr($email,".")) {


I would take a look at using regexp to detect email addresses, rather than stristr. preg_match will use a regular expression, and tell you whether a given string matches that regular expression.

There is a lot of information on validating email addresses using regular expressions here: http://www.regular-expressions.info/email.html
Go to the top of the page
 
+Quote Post
chappill
post May 26 2008, 07:24 PM
Post #3


Member [Level 2]
*****

Group: [HOSTED]
Posts: 88
Joined: 21-April 08
From: Errm...this maps dodgey...i think im in the desert...
Member No.: 61,127



Hmmm now that's confused me :S So I change
CODE
if (!stristr($email,"@") OR !stristr($email,".")) {
to this
CODE
if (!regexp($email,"@") OR !regexp($email,".")) {
??? Or is that wrong, help I'm lost!!!

But thanks for trying, i get into al sorts of problem with my scripts lol.

This post has been edited by chappill: May 26 2008, 07:25 PM
Go to the top of the page
 
+Quote Post
rvalkass
post May 26 2008, 07:39 PM
Post #4


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,156
Joined: 28-May 05
From: Devon, England
Member No.: 7,593
Spam Patrol



No, regexp isn't a function tongue.gif

Regexp stands for regular expressions, and is a way of checking if a string matches a certain pattern. In PHP, the easiest way to use regular expressions is with preg_match. You use it like this:
CODE
preg_match("regexp here", "string to check here");

It will return 0 for no matches, or 1 for a match.

The most difficult part is writing the regexp - the pattern the email address has to match to be classed as valid. Regular expressions are tricky to understand to start with, but incredibly powerful.
Go to the top of the page
 
+Quote Post
chappill
post May 26 2008, 07:59 PM
Post #5


Member [Level 2]
*****

Group: [HOSTED]
Posts: 88
Joined: 21-April 08
From: Errm...this maps dodgey...i think im in the desert...
Member No.: 61,127



Gahhhh my head hurts I need another break already but I'm not off!

I now have:
CODE
preg_match("$email,"@"", "$email,"."");

Instead of:
CODE
if (!stristr($email,"@") OR !stristr($email,".")) {


And that produces the error:
QUOTE
Parse error: syntax error, unexpected '@' in /home/chappill/public_html/test/test/forgot-passwordck.php on line 36

Line 36 is that very line above...It's still screwed and It's all because I'm a retard =[
Go to the top of the page
 
+Quote Post
rvalkass
post May 27 2008, 09:26 AM
Post #6


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,156
Joined: 28-May 05
From: Devon, England
Member No.: 7,593
Spam Patrol



What you want that line to say is this:

CODE
if ( preg_match("^[-._%+A-Za-z0-9]+@[-.A-Za-z0-9]+\.[A-Za-z]{2,4}$", $email) == 0 ) {


The most difficult part to understand is the regexp string, which I will try to explain below. It is basically a pattern that the variable $email must fit to be declared valid. If it fits the pattern, preg_match returns 1, and the email address is valid. If it doesn't fit the pattern, preg_match returns 0, and the email address is invalid.

So, to explain that huge jumble of characters:
  • ^ - The start of the string
  • [-._%+A-Za-z0-9] - Look for the -, ., _, % and + characters, along with characters in the ranges A-Z, a-z and 0-9...
  • + - ...repeated any number of times...
  • @ - ...followed by the @ sign...
  • [-.A-Za-z0-9] - ...then more letters...
  • + - ...repeated any number of times...
  • \. - ...followed by a dot...
  • [A-Za-z] - ...then the letters A-Z and a-z...
  • {2,4} - ...repeated between 2 and 4 times (the domain, like .COM or .UK or something)...
  • $ - ...and then the end of the string.
Go to the top of the page
 
+Quote Post
chappill
post May 30 2008, 02:04 PM
Post #7


Member [Level 2]
*****

Group: [HOSTED]
Posts: 88
Joined: 21-April 08
From: Errm...this maps dodgey...i think im in the desert...
Member No.: 61,127



Sorry it's been about 3 days just got off holidays =].
I put that line in and as I thought it would go ape over
QUOTE
Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in /home/chappill/public_html/test/test/forgot-passwordck.php on line 47


Your email address is not correct
the little ^ thats in there, should that not be something else?
Go to the top of the page
 
+Quote Post
rvalkass
post May 30 2008, 03:24 PM
Post #8


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,156
Joined: 28-May 05
From: Devon, England
Member No.: 7,593
Spam Patrol



Sorry, PHP, for some reason, needs slashes added:

CODE
if ( preg_match("/^[-._%+A-Za-z0-9]+@[-.A-Za-z0-9]+\.[A-Za-z]{2,4}$/", $email) == 0 ) {


Just tested it, and it seems to work. Let us know.
Go to the top of the page
 
+Quote Post
chappill
post May 31 2008, 07:59 AM
Post #9


Member [Level 2]
*****

Group: [HOSTED]
Posts: 88
Joined: 21-April 08
From: Errm...this maps dodgey...i think im in the desert...
Member No.: 61,127



Dude your a star =] Thanks so much for putting up with my dodgy scripts and finding and solving the problem, without you I would