Server side validation (duplicated users)

bubila 26 Nov, 2010
Hello! i've got a problem with server side validation:
Here is the code i put on the ssv box:
<?php
$cf = JRequest::getString('codicefiscale', '', 'post');
$db =& JFactory::getDBO();                           
$sql = "
    SELECT COUNT(*)                               
        FROM `jos_chronoforms_form_iscritti`                   
        WHERE `codicefiscale` =  ".$db->Quote($cf);
";
$db->setQuery($sql);         
$result = $db->loadResult();     
if ( !$result ) {
  return "This user is already in the database ";
}
?>


The problem is that it doesn't work..😟 i get this error anyway, is there anyone who can help?
Thank you so much
GreyHead 26 Nov, 2010
Hi bubila,

What error do you get?

I think that his line
if ( !$result ) {
should be
if ( $result ) {


Bob
bubila 26 Nov, 2010
Hello Bob,
I think you're right! i was in such a hurry that i didn't saw this error...
:)
Sorry but i'm not that expert in php...
THANK YOU SO MUCH
bubila 13 Dec, 2010
i'm back again.. the validation used to work correctly, but today while testing other functionalities, i've tryied again with this one and it doesn't work anymore. Any suggestion?
Thank you so much
Elisa
GreyHead 13 Dec, 2010
Hi Elisa,

Something must have changed if it's stopped working :-(

Impossible to say what from here though.

Bob
bubila 13 Dec, 2010
I've added a filed in the table of the db, but left the code as it was, now i'm trying to add another field in the validation code:
<?php
    $cf = JRequest::getString('codicefiscale', '', 'post');
    $cat = JRequest::getString('categoria', '', 'post');

    $db =& JFactory::getDBO();                           
    $sql = "
        SELECT COUNT(*)                               
            FROM `jos_chronoforms_form_iscritti`                   
            WHERE `codicefiscale` = '".$db->Quote($cf);"' 
            AND 'categoria' = '".$db->Quote($cat);"';
    ";
    $db->setQuery($sql);         
    $result = $db->loadResult();     
    if ( $result ) {
      return "Puoi iscriverti una sola volta per ogni categoria";
    }
?>
but still no success..
the name of the table hasn't changed and neither the field i'm cheking.
did i mess up again with the code?
bubila 13 Dec, 2010
I've cheked your book (form validation and security) and i've update my code as follows:
<?php
$db =& JFactory::getDBO();
$cf = JRequest::getString('codicefiscale', '', 'post');
$cat = JRequest::getString('categoria', '', 'post');
$query = "
  SELECT COUNT(*)
    FROM `#__chronoforms_form_iscritti`
    WHERE `codicefiscale` = '$cf'  AND `categoria` = '$cat' ;
";
$db->setQuery($query);
if ( $db->loadResult() ) {
  return "Sei già iscritto al concorso";
}
?>

and now it works perfectly!
thank you so much!
Elisa
GreyHead 13 Dec, 2010
Hi bubila,

Glad you got it working, well done.

I think perhaps that $db->Quote($xxx) needs to be $db->quote($xxx) (with q instead of Q).

Bob
bubila 13 Dec, 2010
I will try with your suggestion too, to see if it works
thanks again
lopezio 08 Apr, 2011
Hi friends
I'm study Chronoforms from this forum and I have one question: Where is the ssv box? Where I have to write this code?
I need to create a application and I'll try chronoforms. I need to create a login system with validation, and if the user is valid I need to get one field from the table.
Any help will be appreciated
Thank you
GreyHead 08 Apr, 2011
Hi lopezio,

In ChronoForms 3.2 it's on the Form Editor | Validation tab - scroll down the page to see it.

Bob
This topic is locked and no more replies can be posted.