setQuery($sql); $result = $db->loadResult(); if ( $result ) { return "This user is already in the database ";}?>"> Duplicated articles - Forums

Forums

Duplicated articles

proso 21 Feb, 2013
Hi, I'm using 'submit article'. That all works, but now I want to check if that article already exists. So I want to use the field 'onderwerp' to check is it existst in 'jos_content'. I tried the following, but I just don't understand what I'm doing wrong.

I'm using the custom server side validation with this code:
<?php
$cf = JRequest::getString('title', '', 'onderwerp');
$db =& JFactory::getDBO();                           
$sql = "
    SELECT COUNT(*)                               
        FROM `jos_content`                   
        WHERE `title` =  ".$db->Quote($cf);
";
$db->setQuery($sql);         
$result = $db->loadResult();     
if ( $result ) {
  return "This user is already in the database ";
}
?>
GreyHead 21 Feb, 2013
Hi proso,

That looks OK, try echoing out the value of $sql to see exactly what is being created - then test that in PHPMyAdmin to see if you get the expected result.

Bob
proso 22 Feb, 2013
Hi GreyHead,

I don't know how to do that. Could you point me in the right direction?
GreyHead 22 Feb, 2013
Hi proso,

Something like this:
. . .
";
echo'<div>$sql: '.print_r($sql, true).'</div>';
$db->setQuery($sql);  
. . .

Bob
proso 22 Feb, 2013
I guess I'm to much of a noob for this. Is there an other method to check for duplicated articles? Maybe with DB record loader?
GreyHead 24 Feb, 2013
Hi proso,

Possibly, but using a MySQL query like the one you have is probably the easiest way.

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