Hello friends,
Iam Viru, and iam new to the PHP
i want to add list of categories in that,
but iam unable to add those,
but iam not getting any error message also
can any one help me please.
is there any error in these please.
Thank u in Advance
<?
include"functions.php";
include"conn.php";
if($_SERVER['REQUEST_METHOD']=='POST')
{ if(!empty($_GET['id']))
{
$cond="and id<>'".$_GET['id']."'";
}
else
$cond = "";
$sqry="select count(*) as cnt from category where catname='".$_POST['catname']."'".$cond;
$sres=mysql_query($sqry);
$srow=mysql_fetch_assoc($sres);
if($srow['cnt']>0)
{
$dup_msg="Category with this name already exists";
}
else if(empty($_GET['id']))
{ $qur=mysql_query("INSERT INTO `categories` (`catname` , `parentid`) VALUES ('".$_POST['catname']."','0')");
echo '<script language="javascript"> window.location.href="addcat.php?msg=1";</script>';
}
else
{ $qur=mysql_query("UPDATE `categories` SET `catname` = '".$_POST['catname']."' WHERE `id` =".$_GET['id']);
echo '<script language="javascript"> window.location.href="managecat.php?msg=2";</script>';
}
}
if(!empty($_GET['id']))
{ $res=mysql_query("select * from categories where id=".$_GET['id']);
$row=mysql_fetch_array($res,MYSQL_BOTH);
$show="Edit";
}
else
$show="Add";
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Add Category</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style1 {
color: #004080;
font-weight: bold;
}
-->
</style>
<script language="javascript">
function check()
{
var d=document.form1;
if(trimstr(d.category.value)==""){alert("Enter category name");d.category.focus();return false;}
}
function trimstr(str) {
str= this != window? this : str;
return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
</script>
<link href="bungs.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="100%" border="1">
<tr>
<td colspan="3"><? include"top.php";?></td>
</tr>
<tr>
<td colspan="3" bgcolor="#0000FF"></td>
</tr>
<tr>
<td width="18%" valign="top"><? include"left.php";?></td>
<td width="1%" bgcolor="#0000FF"></td>
<td width="81%">
<table width="100%" border="0" >
<tr >
<td align="center" valign="top"><span class="style171"><b><?=$show?> Category</b></span>
<form name="form1" action="" method="post" onSubmit="return check()">
<table width="43%" height="143" border="1" align="center" bordercolor="#004080" >
<tr>
<td height="137" ><table width="100%" border="0" align="center">
<tr>
<td ><table width="92%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="114" align="left"><? if(isset($dup_msg)) {echo $dup_msg; }?></td>
</tr>
<tr>
<td width="114"> </td>
</tr>
<tr>
<td align="right"><span class="style1">Category</span></td>
<td width="7" align="center"><strong>:</strong></td>
<td width="114"><input name="catname" type="text" id="catname"<? if(!empty($_GET['id'])) { ?>value="<?=$row['catname']?>" <? } else { ?> value="" <? } ?>></td>
</tr>
<tr>
<td valign="top"> </td>
</tr>
<tr>
<td height="37"> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3" bgcolor="#0000FF"></td>
</tr>
<tr>
<td colspan="3"><? include"footer.php";?></td>
</tr>
</table>
</body>
</html>