PHP Newsletter

Join now and receive weekly updates pertianing to the world of PHP.

Polls

What do you think about the new PHPMine Design?
Awesome
Not Bad
Sucks

PHP Gigs By City

PHP Jobs By Topic

Advertisements

PhP - MySQL Validation issue?

Asked 2010-03-09 12:29:33 by 24JJ24

Hi,

I am trying to get some code straight. I know its a bit messy, apologies. The aim of the script is that if the email matches a regex expression (previously defined), then it checks the database to see if the email the user has entered is already there. If it is, it prints back a message telling the user to enter a new one.

The database field itself is unique, so technically there will be no other email that is the same, however for the sake of having to redirect the user back I'd like to just keep all the validation on one page.

However, when I enter an email that already exists in the database, it still lets me continue to the database page. Not sure why this is, can anyone help me out?

Thanks

--------------------------------------…

$email = clean($_POST['Email1']);
<tr>
<td><div class="<?php print $emailclass; ?>">Email Address:*</div></td>
<td><input type="text" name="Email1" value="<?php print $email; ?>" size="30"/></td>
</tr>
<?php

if ($emailvalidationcheck == "NOTOK"){
$flag = "NOTOK";
print '<tr><td align="center" colspan="2" class="errorsubtext"> Please enter a valid Email Address. </td></tr>';
}
else if ($emailvalidationcheck == "OK"){
$sql = "select count(*) from `".$tbl_name."` where `customer_email_address` = '" .mysql_real_escape_string($email). "'";
$list = mysql_query($sql);
$lst = mysql_fetch_array($list);
$count = $lst[0];
mysql_free_result($list);
if($count >= 1){
$emailclass = "errortext";
$flag="NOTOK";
print '<tr><td align="center" colspan="2" class="errorsubtext"> This email address is already in use. </td></tr>';
}
else if($count ==0){
$emailclass = "basictext";
$flag="OK";
}}

?>

Anwered 2010-03-09 12:45:05 by Aqeel

$count=$lst[0];

has an error.

if you want to count number of elements in an array use count() or sizeof()

$count=count($lst);

this will work

Questions and answers provided by the Yahoo Answers Community.