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">&nbsp;</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">&nbsp;</td>
              </tr>
              <tr>
                <td height="37">&nbsp;</td>
                <td>&nbsp;</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>

Recommended Answers

All 9 Replies

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.

Thank u in Advance

Hi Viru..
can u send me ur code....(from where u getting categories..)
i will try it..

Thanks for reply Ms.Saritha
i sended the code just now please

Virspy

try echo your insert query.....

Thanks Ms.Shanti

Iam getting but we will write some ting in conn file to dispaly error msg na

viru

MS.Shanti
iam Getting this type of error
can u please

mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\www\testing\addcat.php on line 13

Viruspy

check your table name once...
you mentioned category at line 13 and categories at rest of the code..
please check it once and try...

i changed that iam getting same error please

change this line:
$sres=mysql_query($sqry);

to be like this:
$sres=mysql_query($sqry) or die(mysql_error());

this will tell you what the problem is.

if your thread got solved...
make it solved ....always...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.