Location: PHPKode > scripts > Create Your Own Directory > cms/admin/editcntfield.php
<?php
require_once "../auth/config.php";
$link = mysql_connect($hostname, $username,$password);
$res=mysql_select_db($dbname,$link);
$sno=$_GET['sno'];
$catid=$_GET['catid'];
$oldval=$_GET['oldval'];
$opr=$_GET['opr'];
$fname=$_GET['fname'];
$ftype=$_GET['ftype'];
$inputtype=$_GET['inputtype'];
$defaultval=$_GET['defaultval'];
$contentpg=$_GET['contentpg'];
$mandatory=$_GET['mandatory'];


	if($opr=="update"){
		If($catid !="" && $fname != "" && $ftype!= "" && $inputtype != "" && $contentpg != "" && $mandatory !="")
      	{
           		$duplicate="no";
			$qry="select * from cntfields where catid=$catid and fname='$fname'";
             	$res=mysql_query($qry,$link);
                  $i=0;
                	while($line = @mysql_fetch_array($res,MYSQL_ASSOC))
		    	{
                   $i=$i+1;	
                	}
			
                  if($i>=2)
			{
                    $duplicate="present";
			}
              	if($duplicate == "no")
              	{   

                   	$qry1="update cntfields set fname='$fname',ftype='$ftype',inputtype='$inputtype',defaultval='$defaultval',contentpg=$contentpg,mandatory=$mandatory where catid=$catid and fname ='$oldval'";
             		$res1=mysql_query($qry1,$link);
                  	if($res1){
			  		echo"$sno----Your content is updated into database";
                  	}else{
			  		echo"$sno----Enter gsfg proper values into madatory fields";
                  	}

              	}else{
			     	echo"$sno----Field name your are trying to add is already present ";
                 }
           	}else{
            	echo"$sno----Enter proper values into madatory fields";
            }
      }else if($opr=="delete")
	{
      	$cntpresent="no";
            $query="select contents from  cnt where tid=$catid";
 		$result=mysql_query($query,$link);
            while($row = @mysql_fetch_array($result, MYSQL_ASSOC))
		{
			$cntpresent=$row['contents'];
            }

		if($cntpresent=="no"){
			$qry2="delete from cntfields  where catid=$catid and fname ='$oldval'";
             	$res2=mysql_query($qry2,$link);
                  if($res2){
				  echo"$sno----Your field is deleted from content field list";
      	      }

            }else{
			$k=0;
                  $qq="select * from cntfields where catid=$catid";
 			$res=mysql_query($qq,$link);
                  while($row = @mysql_fetch_array($res, MYSQL_ASSOC))
			{
				$fname=$row['fname'];
                        if($fname!="$oldval"){
                        $k++;
                        }else{
                      
                        break;
                        }
                  }
			$st="";
			$qry2="delete from cntfields  where catid=$catid and fname ='$oldval'";
             	$res2=mysql_query($qry2,$link);
                  $qr="select cntid,contents from cnt where tid=$catid";
			$ree=mysql_query($qr,$link);
                  while($row = @mysql_fetch_array($ree, MYSQL_ASSOC))
			{	

				$cntid=$row['cntid'];
				$contents=$row['contents'];
                        $arr=split('####',$contents);
                        $ct=count($arr);
                        $st="";
                          for($i=0;$i<$ct-1;$i++){
                            if($i != $k)
                            {
					$st=$st.$arr[$i]."####";
                            }
    					
                         }
                    $rr="update cnt set contents='$st' where cntid=$cntid and tid=$catid";
                     	$ress=mysql_query($rr,$link);
                   }
                   if($ress){
				echo"$sno----Your field is deleted from content field list,along with the field value present in content table ";
                   }else{
                        echo"$sno----issue in deleting content fields which contain content in content table ";
                 }
                
            }
	}
               
           
?>

Return current item: Create Your Own Directory