SGL Error in J3.3.4

SPABO 04 Oct, 2015
After the migration from J2.5 to J3.4, including (re) installing Chronoforms V

When opening a form in FE, I'm getting this message

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM GROUP BY ORDER BY' at line 1 SQL=SELECT FROM GROUP BY ORDER BY



The SQL statement in the formcode is as follows:
<?php
//Fetch a list of different dates with registrations
$db = JFactory::getDBO();
$query = 'SELECT %2$s FROM %1$s GROUP BY %2$s ORDER BY %2$s';
$pst = sprintf($query,
  $db->nameQuote('J25_chronoforms_data_Bussloo'),
  $db->nameQuote('datum')
);
$db->setQuery($pst);
$items = $db->loadObjectList();
?


The code in the EVENT after SUBMIT is as follows:
<?php
$db = JFactory::getDBO();
$query = 'SELECT %s, %s, %s, %s, %s, FROM %s WHERE %s = %s';
$pst = sprintf($query,
  $db->nameQuote('lidcode'),
  $db->nameQuote('voornaam'),
  $db->nameQuote('tussenvoegsel'),
  $db->nameQuote('achternaam'),
  $db->nameQuote('pphcp'),
  $db->nameQuote('J25_chronoforms_data_Bussloo'),
  $db->nameQuote('datum'),
  $db->Quote(JRequest::getString('datum'))
);
$db->setQuery($pst);
$items =& $db->loadObjectList();
?>


This coding and SQL worked fine in J2.5, but now I'm getting the error

Any ideas Bob ?
GreyHead 04 Oct, 2015
Hi SPABO,

$db->nameQuote() has apparently been deprecated since Joomla! 1.6 and removed in Joomla! 3. The replacement appears to be $db->quoteName()

Bob
SPABO 04 Oct, 2015
Nope, I changed all the $db->nameQuote tp $db->quoteName and now getting this error:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `J25_chronoforms_data_Bussloo` WHERE `datum` = '23-09-2015'' at line 1 SQL=SELECT `lidcode`, `voornaam`, `tussenvoegsel`, `achternaam`, `pphcp`, FROM `J25_chronoforms_data_Bussloo` WHERE `datum` = '23-09-2015'
GreyHead 04 Oct, 2015
Hi SPABO,

Actually . . . Yes, that was the right answer - the problem you now have is a different typo in your code.

It looks to me as if there is an unwanted comma in your query string.

Bob
SPABO 04 Oct, 2015
Strange, as said, I change only the nameQuote to quoteName.

The forms in the J25 period went perfectly!
HTML Code:

<?php
//Fetch a list of different dates with registrations
$db = JFactory::getDBO();
$query = 'SELECT %2$s FROM %1$s GROUP BY %2$s ORDER BY %2$s';
$pst = sprintf($query,
  $db->quoteName('J25_chronoforms_data_Bussloo'),
  $db->quoteName('datum')
);
$db->setQuery($pst);
$items = $db->loadObjectList();
?>
<div class="ccms_form_element cfdiv_select" id="datum_container_div"><label for="datum">Wedstrijddatum</label><select size="1" class=" validate['required']"id="datum" title="Vul hier uw keuze in." select name="datum">
<option value="">Kies wedstrijddatum</option>
<?php
foreach ($items as $item) {
  echo('<option value="' . $item->datum . '">' . $item->datum . '</option>');
}
?>
</select>
</div>
<div class="cfclear"></div>


After Submit code
<?php
$db = JFactory::getDBO();
$query = 'SELECT %s, %s, %s, %s, %S, FROM %s 
WHERE %s = %s';
$pst = sprintf($query,
  $db->quoteName('lidcode'),
  $db->quoteName('voornaam'),
  $db->quoteName('tussenvoegsel'),
  $db->quoteName('achternaam'),
  $db->quoteName('pphcp'),
  $db->quoteName('J25_chronoforms_data_Bussloo'),
   $db->quoteName('datum'),
  $db->Quote(JRequest::getString('datum'))
);
$db->setQuery($pst);
$items =& $db->loadObjectList();
?>
<center><div class="form_item">
<div class="form_element cf_heading">
<h3 class="cf_text">Deelnemerslijst P&P Bussloo</h3>
<h5 class="cf_text">d.d. 23 september 2015</h5>
<br>
<div class="cfclear"></div>
</div>
</div>
<table style="text-align: left; width: 285px;" border="1"
 cellpadding="1" cellspacing="1">
<thead>
<tr>
<tbody>
<th>Lidcode</th><th>Voornaam</th><th>_________</th><th>Achternaam</th><th>PP-HCP</th>
</tr>
</thead>

<?php
foreach ($items as $item) {
  echo('<tr><td>' . $item->lidcode . '</td><td>' . $item->voornaam . '</td><td>' . $item->tussenvoegsel . '</td><td>' . $item->achternaam . '</td><td>' . $item->pphcp . '</td></tr>');
}
?>
</tbody></table>				
<br><br><br>


So I'm puzzled again
GreyHead 04 Oct, 2015
Hi SPABO,

Did you try removing the extra comma?

Bob

PS This is nothing directly to do with ChronoForms or the way it runs, it's just that your custom PHP isn't producing valid SQL
SPABO 04 Oct, 2015
Hi Bob,
If I would know hwre I would remove it....

Why does it not producing a valid SQL? It always did in J2,5!!
GreyHead 05 Oct, 2015
HI SPABO,

Check the error message you posted
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 
'FROM `J25_chronoforms_data_Bussloo` WHERE `datum` = '23-09-2015'' 
at line 1 
SQL=SELECT `lidcode`, `voornaam`, `tussenvoegsel`, `achternaam`, `pphcp`, FROM `J25_chronoforms_data_Bussloo` WHERE `datum` = '23-09-2015'
it looks to me as though the , before FROM is incorrect.

Bob
SPABO 05 Oct, 2015
Bob,
I changed:
$query = 'SELECT %s, %s, %s, %s, %S, FROM %s

into
$query = 'SELECT %s, %s, %s, %s, %S FROM %s


That was the solution.

Saying this: The comma has been there for many years in the J25 period...

Anyway, this was the solution.

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