0

hi...
i have this error in my code
Fatal error: Call to undefined method myclass::addCat() in G:\AppServ\www\society\Admin\addCat.php on line 23

this is aclass function

function addCat($t1)
  {
      mysql_query("insert into categories (Categoriesname)values ('$t1')") or die(mysql_error());}

and this aline have a error

if (isset($_POST['but1']))
{ $t1=$_POST['txt1'];
$m= new myclass();
$m->addCat($t1);
    }

I dont no where is the problem???

3
Contributors
9
Replies
21
Views
4 Years
Discussion Span
Last Post by hanan-kh
0
<?php
session_start();
include("myclass.class.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<title>ادارة التصنيفات</title>
</head>

<body>
<?php
if(!isset($_SESSION[username]))

{
?><script type="text/javascript">

     window.location = "index.php";
     </script> 
<?php } 
if (isset($_POST['but1']))
{ $t1=$_POST['txt1'];
$m= new myclass();
$m-> addCat($t1);

    }
?>

<div align="center" style="width:900px;
    height:1000px;
    background-color:#d9d9d9;
    margin-left:250px;
    margin-top:0px;
    border-radius:5px 5px 5px 5px;
    color:#114b8f;
    text-align:right;">
<div style="float:right; width:80px ; margin-right:100px;"> <?php include("cpmenu.php");?> </div>
<div style="float:left; margin-top:20px; margin-left:20px;">
<form action="addCat.php" method="POST" enctype="multipart/form-data" name="form">
<fieldset style=" border-color:#06F; width:630px;"><legend>إضافة تصنيف جديد</legend>
<input name="but1" type="submit" value="اضافة" />
<input name="txt1" type="text" size="30" style="text-align:right;" /><label>اسم التصنيف</label>



</fieldset>
</form>

</div>
</div>
</body>
</html>

thats add Categories code and its error file

<?php
class myclass{



function __construct(){
    $conn=mysql_connect("localhost","root","1");
    mysql_select_db("society",$conn);


    }

function validlogin($t1,$t2)
{ mysql_query("set names 'cp1256';");
$res = mysql_query("select * from admin where username = '$t1' and pass = '$t2'");
  $count = mysql_num_rows($res);

  if($count== 0)
  return false;
  else
  return true;
}
function addCat($t1)
  {
      mysql_query("insert into categories (Categoriesname)values ('$t1')") or die(mysql_error());
      }
?>
0

include("myclass.class.php");

check if the name of the file myclass.class.php is correct and if both files are in the same folder.

also you are missing } at the end of the myclass.class.php file

Edited by dorco

0

I think I finally found it.

you are submitting the data called addCat.php that is not been even used in addCat.php because in addCat.php, it is just only a list of codes of functions. so the data that has passed from your previous is not used.

because the $m->addCat($t1); is located at the head tag of your previous page.

I think you want this way

1.)remove your if(isset($_POST['but1'])) block because you havent yet used to pass data from a form of the said page you want to add a category. paste before the myClass()

or

2.)edit the action attribute of form tag to action="<?php htmlspecialchars($_SERVER['PHP_SELF']);?>" then at next line after head tag is to include addCat.php by using either include() or require()

Edited by masterjiraya

0

I've tried everything you asked me, but unfortunately still the problem exists
I was very tired and I'm trying to solve it for more than two days ..

0

just a repost...

I think I finally found it.

you are submitting the data called addCat.php that is not been even used in addCat.php because in addCat.php, it is just only a list of codes of functions. so the data that has passed from your previous is not used.

because the $m->addCat($t1); is located at the head tag of your previous page.

I think you want this way

1.)remove your if(isset($_POST['but1'])) block because you havent yet used to pass data from a form of the said page you want to add a category. paste before the myClass()

or

2.)edit the action attribute of form tag to action="<?php htmlspecialchars($_SERVER['PHP_SELF']);?>" then at next line after head tag is to include addCat.php by using either include() or require()

0

Thank you have tried the first option and succeeded not know what to say I am very happy and I thank you again

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.