<?php
ob_start();

include 'func.php';
require_once 'htmlhead.php';
?>
<?php
if(isset ($_POST['submit']) && $_POST['submit']=='Add') {
    $cat_name = $_POST['c_name'];
    $qry = 'insert into category (name) values ("' . mysql_escape_string($cat_name) . '")';
    $result=@mysql_query($qry);
    if($result)
        echo "<div style='margin-top:15px;color:green'>Added Successfully</div>";
    else
        echo "<div style='margin-top:15px;color:red'>Error In Adding Data</div>" ;

        
}
if(isset ($_POST['submit']) && $_POST['submit']=='Delete') {
    //echo $_POST['c_id'];
     $qry = 'delete from category where category_ in (' . $_POST['c_id']. ')';
     $result=  @mysql_query($qry);
     if($result)
        echo "<div style='margin-top:15px;color:green'>Deleted Successfully</div>";
    else
        echo "<div style='margin-top:15px;color:red'>Error In Deleting Data</div>";
    
}
if(isset ($_POST['submit']) && $_POST['submit']=='Edit') {
     //echo $_POST['c_id'];echo $_POST['c_name'];
     $qry = 'update category set name = "' . mysql_escape_string($_POST['c_name']) . '" where category_ = ' . mysql_escape_string($_POST['c_id']);
     $result=@mysql_query($qry);
     if($result)
        echo "<div style='margin-top:15px;color:green'>Edited Succesfully </div>";
    else
        echo "<div style='margin-top:15px;color:red'>Error In Editing Data</div>";

}
?>
<br/><br/>
<table>
    <form  action="" method="post">
        Add New Category : <input type="text" name="c_name" />
        <input type="hidden"  name="action" value="Add" />
        <input type="submit" name="submit" value="Add" />
    </form>
</table>
<br/><br/>
<?php
$qry = 'select * from category';
$category_res = mysql_query($qry) or die(mysql_error());

@mysql_data_seek($category_res, 0);
$cnt = 0;
while (($row=mysql_fetch_assoc($category_res))!==false) {
    $cnt++;
    ?>
<table>

    <tr>
    <form action="" method="post">
        <input type="hidden" name="c_id" value="<?php  echo $row['category_']; ?>">
        <td>
            <input type="text" name="c_name" value="<?php echo $row['name']; ?>"/>
        </td>
        <td>&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" value="Edit">&nbsp;&nbsp;</td>&nbsp;&nbsp;
        <td><input type="submit" name="submit" value="Delete">&nbsp;&nbsp;</td>&nbsp;&nbsp;
        </form>
    </tr>
</table>

    <?php
}

?>
<?php require_once 'htmlfoot.php'; ?>