Forums

Email duplication - solved

spletcher 10 May, 2009
Max,

I'm trying to do the server side validation for an email. I'm using the following code in the server side validation code box but it doesn't seem to work.

<?php
$ref_num = JRequest::getVar('text_4', '', 'post');

$db =& JFactory::getDBO();
$query = "
SELECT count(*)
FROM `#__users`
WHERE `ref_num` = ".$db->Quote($quote)." ;
";
$db->setQuery($query);
$in_use = $db->loadResult();
if ( $in_use) {
return "That email is already registered, please try again";
}
?>
GreyHead 10 May, 2009
Hi spelcher,

A bit late for me but I think that
WHERE `ref_num` = ".$db->Quote($quote)." ;
should be
WHERE `ref_num` = ".$db->Quote($ref_num)." ;
as $quote isn't defined here.

Bob
spletcher 10 May, 2009
thanks. I've changed that but no success yet.

I got this code from one of Max's posts on preventing duplication of table entries.
GreyHead 11 May, 2009
Hi spletcher,

The second problem is that there isn't a field called ref_num in jos_users, the email field is `email` so the code needs to be

<?php
$email = JRequest::getVar('text_4', '', 'post');

$db =& JFactory::getDBO();
$query = "
  SELECT count(*)
    FROM `#__users`
    WHERE `email` = ".$db->Quote($email)." ;
";
$db->setQuery($query);
if ( $db->loadResult()) {
  return "That email is already registered, please try again";
}
?>

Bob
spletcher 11 May, 2009
Awesome - that fixed it.

Whoops - I should have seen that one!!
This topic is locked and no more replies can be posted.