Forums

Event Switcher to check database

Tarrel 23 Jan, 2015
I'm working a while now with this fantastic component, thanks for that!!
But I'm stuck with a problem which I am not able to fix.

I have a database named 'Koper-ID' which has one column 'Koper-ID'.
In my form I have a field named 'Koper-ID'.

When somebody is filling the form, the he puts into the field 'Koper-ID' should be checked within the database.
When the number is found in the database it's a success otherwise a fail. Both events have a simple message displayed.

In the 'on submit' section I made an 'Event switcher' with this code:
$db = JFactory::getDbo();
 $user = JFactory::getUser();
  
 $query = $db->getQuery(true);
 $query= SELECT * FROM `hyn4b_Koper-ID` WHERE 'Koper-ID'=.$user->get("Koper-ID").;
 $db->setQuery($query);
 $db->query();
 $num_rows = $db->getNumRows();

 if ($num_rows==0){return "success";}
    else{return "fail";}


But no mather what I fill into the form, when I submit, I receive this:
$db = JFactory::getDbo(); $user = JFactory::getUser(); $query = $db→getQuery(true); $query= SELECT * FROM ‚hyn4b_Koper-ID‚ WHERE ‚Koper-ID’=.$user→get(„Koper-ID”).; $db→setQuery($query); $db→query(); $num_rows = $db→getNumRows(); if ($num_rows==0){ return „success”; }else{ return „fail”; }

What am I doing wrong?
Thanks in advance
Max_admin 23 Jan, 2015
Hi Tarrel,

The code should start with a PHP tag:
<?php


it also has some other mistakes, please try the following line instead of yours:
$query= "SELECT * FROM `hyn4b_Koper-ID` WHERE 'Koper-ID'='".$form->data("Koper-ID")."'";


Alternatively you may use a "DB Read" action and use the conditions box to supply the field value!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Tarrel 24 Jan, 2015
Hi Max,

Thanks for your quick reply. Maybe a using "DB Read" is better and more simple.
But I really know nothing about php, can you help with the conditions for this Koper-ID?

Thanks,
Tarrel
Tarrel 24 Jan, 2015
I found an old message of yours on this forum, I used the code below and it works!
<?php
 return array("Koper-ID" => $form->data("Koper-ID")); ?>


Thanks again!
Tarrel
GreyHead 24 Jan, 2015
Hi Tarrell,

Please see this FAQ for more on WHERE clauses in CCv5 and CFv5 (they both work in the same way).

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