chriscapetown 0 Newbie Poster

Hi,

Im having trouble getting this piece of code to function correctly. It inserts the data fine, and all works well, but I cant seem to make it only insert if there isnt already an entry with the same $text.

What I want it to do is this:

Insert the data to the table, but if it is going to make a duplicate on entry, then update the existing entry with the new data.

Any help would be much appreciated!

Thanks,
Chris

$shout='[iurl='.sefRelToAbs('index.php?option=com_comprofiler&task=userProfile&user='.$cms->user->id.'&Itemid=140').']'.$cms->user->name.'[/iurl] just wrote a blog titled [iurl='.cmsSefAmpReplace('index.php?option=com_myblog&show='.$this->permalink.'&Itemid=316').']'.stripslashes($this->title).'[/iurl]';
//$database->setQuery("INSERT INTO #__liveshoutbox (time,name,text,url) VALUES ('".time()."','Blogs','".mysql_real_escape_string($shout)."','')");
//$res = $database->query();

$database->setQuery("INSERT INTO #__liveshoutbox (time, name, text, url) VALUES ('".time()."','Blogs','".mysql_real_escape_string($shout)."','') ON DUPLICATE KEY UPDATE text = '$shout'");
$res = $database->query();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.