Location: PHPKode > scripts > PHP Reciprocial Links > php-reciprocial-links/admin/add_rec_cat.php
<?
include_once("myconnect.php");
include_once("logincheck.php");


function main()
{

if ( isset( $_REQUEST["cid"] ) && $_REQUEST["cid"]!="" )
{
$cid=$_REQUEST["cid"];
}
else
{
$cid=0;
}
$cat_name="";
$cat_desc="";

  
?>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#75A7AC">
  <tr> 
    <td valign="top"> <table width="100%" border="0" cellpadding="1" cellspacing="1" dwcopytype="CopyTableCell">
        <tr> 
          <td valign="top" bgcolor="F5F5F5"><table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr> 
                <td>&nbsp;</td>
              </tr>
              <tr> 
                <td valign="top"> 
                  <?

$errcnt=0;
$showform="";

$mailid="";
$fromid="";
$subject="";
$mail="";

if ( count($_POST)!=0 )
{

if ( !isset( $_REQUEST["catname"] ) || $_REQUEST["catname"]=="" )
{
	$errs[$errcnt]="Category name must be provided";
    $errcnt++;
}
else
{
$par_cat=mysql_fetch_array(mysql_query("select * from sbreciprocal_cats where catname='".str_replace("'","''",$_REQUEST["catname"])."' and pid=".$_REQUEST["cid"]));
 if($par_cat)
 {
	$errs[$errcnt]="Category with this name already exists.";
    $errcnt++;
 }
}

if ( !isset( $_REQUEST["catdesc"] ) || $_REQUEST["catdesc"]=="" )
{
	$errs[$errcnt]="Category description must be provided";
    $errcnt++;
}
$num_ques=mysql_num_rows(mysql_query("select * from reciprocal_links where cid=".$_REQUEST["cid"]));
if( $num_ques>0)
{
	$errs[$errcnt]="This category contains $num_ques articles, you have to shift all these articles to any other category before adding a subcategory.";
    $errcnt++;
}

}
?>
                  <p align="center"> 
                    <?
if  (count($_POST)<>0)
{
if ( $errcnt==0 )
{
			if (!get_magic_quotes_gpc()) {
			$catname=str_replace('$', '\$',addslashes($_REQUEST["catname"]));
			$catdesc=str_replace('$', '\$',addslashes($_REQUEST["catdesc"]));
			}
			else
			{
			$catname=str_replace('$', '\$',$_REQUEST["catname"]);
			$catdesc=str_replace('$', '\$',$_REQUEST["catdesc"]);
			}

$sql="Insert into sbreciprocal_cats (catname,catdesc,pid) values ('$catname','$catdesc',".$_REQUEST["cid"].")";
$rs=mysql_query( $sql);

?>
                    <br>
                    <br>
                    <strong><font color="#FF0000" size="2" face="Arial, Helvetica, sans-serif">Category 
                    has been Added</font></strong> 
                    <?
$showform="No";
}
else
{
$cat_name=$_REQUEST["catname"];
$cat_desc=$_REQUEST["catdesc"];


?>
                  </p>
                  <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr> 
                      <td colspan="2">&nbsp;</td>
                    </tr>
                    <tr> 
                      <td colspan="2"><font color="#FF0000" size="2" face="Arial, Helvetica, sans-serif"><strong>Your 
                        Add Category Request cannot be processed due to following 
                        Reasons</strong></font></td>
                    </tr>
                    <?

for ($i=0;$i<$errcnt;$i++)
{
?>
                    <tr valign="top"> 
                      <td width="6%"><strong><font color="#FF0000"><?php echo $i+1; ?></font></strong></td>
                      <td width="94%"><font color="#FF0000" size="2" face="Arial, Helvetica, sans-serif"><?php echo  $errs[$i]; ?> 
                        </font></td>
                    </tr>
                    <?
}//end for
?>
                  </table>
                  <?

}

}


?>
                  <font color="#FF0000" size="2" face="Arial, Helvetica, sans-serif"> 
                  <?
	   if (isset($delmsg))
	   {
	   echo $delmsg;
	   }
	   ?>
                  </font> 
                  <form name="form2" method="post" action="add_rec_cat.php">
                    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                      <tr> 
                        <td colspan="3" align="center" bgcolor="#CCCCCC"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Add 
                          New 
                          <? if($cid<>0) { echo "Subcategory";} else { echo "Catergory";}?>
                          </font></strong></td>
                      </tr>
                      <tr> 
                        <td colspan="2">&nbsp;</td>
                        <td width="448">&nbsp;</td>
                      </tr>
                      <tr> 
                        <td width="139" align="right"><div align="left"><font size="2" face="Arial, Helvetica, sans-serif">Catergory 
                            Name:</font></div></td>
                        <td width="14"><font size="2" face="Arial, Helvetica, sans-serif">&nbsp;</font></td>
                        <td><font size="2" face="Arial, Helvetica, sans-serif"> 
                          <input name="catname" type="text" value="<? echo $cat_name;?>" size="40">
                          </font></td>
                      </tr>
                      <tr> 
                        <td colspan="2"><div align="left"><font size="2" face="Arial, Helvetica, sans-serif">&nbsp;</font></div></td>
                        <td><font size="2" face="Arial, Helvetica, sans-serif">&nbsp;</font></td>
                      </tr>
                      <tr> 
                        <td align="right"><div align="left"><font size="2" face="Arial, Helvetica, sans-serif">Description:</font></div></td>
                        <td><font size="2" face="Arial, Helvetica, sans-serif">&nbsp;</font></td>
                        <td><font size="2" face="Arial, Helvetica, sans-serif"> 
                          <textarea name="catdesc" cols="35"><? echo $cat_desc;?></textarea>
                          </font></td>
                      </tr>
                      <tr> 
                        <td colspan="2">&nbsp;</td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr> 
                        <td><font size="2" face="Arial, Helvetica, sans-serif">Category:</font></td>
                        <td><font face="Arial, Helvetica, sans-serif" size="2">&nbsp; 
                          </font></td>
                        <td><font face="Arial, Helvetica, sans-serif" size="2"> 
                          <select name="cid" id="select" >
						  
                            <?
				  $rs_query=mysql_query("select * from sbreciprocal_cats order by pid");
				  
				  while($rst=mysql_fetch_array($rs_query))
				  {
				  $cat_path="";
		$child=mysql_fetch_array(mysql_query("select * from sbreciprocal_cats where pid=".$rst["id"]));
									  
									  $cat_path.=$rst["catname"];
		 $par=mysql_query("select * from sbreciprocal_cats where id=".$rst["pid"]);
		 				while($parent=mysql_fetch_array($par))
		 				{
						$cat_path=$parent["catname"].">".$cat_path;
						$par=mysql_query("select * from sbreciprocal_cats where id=".$parent["pid"]);
						}
                                      ?>
                            <option value="<? echo $rst["id"];?>" <?php
				if ( $rst["id"]==$cid )
				{
				echo "  selected ";
				}
				?>><? echo $cat_path;?></option>
                            <?
									  }
									  ?>
                          </select>
                          <input type="submit" name="Submit" value="Add">
                          </font> </td>
                      </tr>
                      <tr> 
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr> 
                        <td colspan="3"><div align="center"><font color="#FF0000" size="2" face="Arial, Helvetica, sans-serif">.</font></div></td>
                      </tr>
                    </table>
                  </form>
                  <?


?>
                </td>
              </tr>
            </table></td>
        </tr>
      </table></td>
  </tr>
</table>
<?
}  //End of main
include_once("template.php");
?>
Return current item: PHP Reciprocial Links