checking the same name in db and if there is add 2 etc at the end


/ Published in: PHP
Save to your folder(s)

a function which tests the submitted page name. If that name is the
same as another page which has the same parent, then a number is added to the end
and a message is shown explaining this.


Copy this code and paste it in your HTML
  1. function pages_setup_name($id,$pid){
  2. $name=trim($_REQUEST['name']);
  3. if(dbOne('select id from pages where
  4. name="'.addslashes($name).'" and parent='.$pid.'
  5. and id!='.$id,'id')){
  6. $i=2;
  7. while(dbOne('select id from pages where
  8. name="'.addslashes($name.$i).'" and parent='.$pid.'
  9. and id!='.$id,'id'))$i++;
  10. echo '<em>A page named "'.htmlspecialchars($name).'"
  11. already exists. Page name amended to "'
  12. .htmlspecialchars($name.$i).'".</em>';
  13. $name=$name.$i;
  14. }
  15. return $name;
  16. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.