The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End How to write this condition? Re: How to write this condition?


Thanks Hugo , the script did not work but that gave me an idea
I have written another script

$title= mysql_real_escape_string($_POST);
$slug=str_replace(‘ ‘, ‘-‘, $title);

$query=mysql_query(“SELECT * FROM pages WHERE slug=’$slug’ “);

$slug2= $slug;
if(preg_match(‘/[a-zA-Z0-9-]+~[0-9]/’, $slug)){
$dash_pos= strrpos($slug, ‘~’);
$str_len= strlen($slug);
$after_dash= substr($slug,$dash_pos+1, $str_len );
$slug2= str_replace($after_dash,$after_dash+1,$slug);
//main if statememt ENDS
$slug= mysql_real_escape_string($_POST);
$slug2=str_replace(‘ ‘, ‘-‘, $slug);

$query= mysql_query(“INSERT INTO pages(pagename, content, pageId, slug, date, time, count) VALUES(‘$title’, ‘$content’, ‘$pageId’, ‘$slug2’, ‘$date’,’$time’, ‘$count’)”);

The code above is creating another slug
First it creates just ‘about-us’
then ‘about-us~1’
and if I do it again , it returns
‘about-us~1’ only.
What do I do?? ):