Anything wrong?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

thinking that you only want to do your db insert if the email passes the test.

Code: Select all

if(preg_match("/(\<|\>)/", $_POST['uname'])) {
        die('Invalid input, no tags < or > are allowed in your username.');
} 
if (preg_match("^[a-z0-9\._-]+@([a-z0-9][a-z0-9-]*[a-z0-9]\.)+([a-z]+\.)?([a-z]+)^",$_POST['email']))
{
$rand = rand(10248765,99543547);    
mysql_connect("localhost", "admin", "ak7456") or die(mysql_error());
mysql_select_db("users") or die('Sorry, we are having database connection problems, please report this to an Administrator');    
$regdate = date('m d, Y');
$chrctr =  $_POST['email'];   
$qry = "INSERT INTO users (username, password, regdate, email) VALUES ('".$_POST['uname']."', '".$rand."', '".$regdate."', '".$_POST['email']."')";    
mysql_query($qry)  or die(mysql_error());    
mysql_query("INSERT INTO stats('".$_POST['uname']."','$chrctr', '100', '2000', '001', '01', 000, '01', '01', '01', '1', '0', '00000000', '00000000', '00000000', '00000000')");    
mysql_close();    
print "You successfully registered as'".$_POST['uname']."'";
}
else{
die{'Email Adress invalid, you entered: '.$_POST['email'].''};
}
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

Thanks, good point, but I still have the error on the same line.

My code:

Code: Select all

<?php
if(preg_match("/(\<|\>)/", $_POST['uname'])) {
        die('Invalid input, no tags < or > are allowed in your username.');
} 
if (preg_match("^[a-z0-9\._-]+@([a-z0-9][a-z0-9-]*[a-z0-9]\.)+([a-z]+\.)?([a-z]+)^",$_POST['email'])){
$rand = rand(10248765,99543547);    
mysql_connect("localhost", "admin", "ak7456") or die(mysql_error());
mysql_select_db("users") or die('Sorry, we are having database connection problems, please report this to an Administrator');    
$regdate = date('m d, Y');$chrctr =  $_POST['email'];   
$qry = "INSERT INTO users (username, password, regdate, email) VALUES ('".$_POST['uname']."', '".$rand."', '".$regdate."', '".$_POST['email']."')";    
mysql_query($qry)  or die(mysql_error());    
mysql_query("INSERT INTO stats('".$_POST['uname']."','$chrctr', '100', '2000', '001', '01', 000, '01', '01', '01', '1', '0', '00000000', '00000000', '00000000', '00000000')");    
mysql_close();    
print "You successfully registered as'".$_POST['uname']."'";
}
else{die{'Email Adress invalid, you entered: '.$_POST['email'].''};
}
?>
On line 16
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

Anyone :?: :(
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Just temporarily, for troubleshooting's sake. Remove the pregs and put something else in your conditions (something valid of course) - I'm guessing it's one of those.

EDIT | More specifically... take out the email validation preg_match()... ;) I think we'll have to rewrite that one :P (d11 get's excited )
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

Tried that, still get the error on line 19:

Code: Select all

die{'Email Adress invalid, you entered:'.$_POST['email'].''};
This is a different line than what I had an error on before.... I think :?
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

Any ideas? :D
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Parody wrote:

Code: Select all

die{'Email Adress invalid, you entered:'.$_POST['email'].''};
This is a different line than what I had an error on before.... I think :?
Ummmm yeah.... that's not right. Parentheses, not curlies....

I'm amazed nobody spotted that (incl. me) :?
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

Can you just give me a quick lesson on the difference between () and {} and when to use each please?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Read my hint in a thread of you with a similar problem... viewtopic.php?t=34482
Post Reply