天天看點

php 調用未定義方法,php – “調用未定義函數”錯誤時調用類方法

這是錯誤緻命錯誤:調用未定義的函數assign(

這是代碼,你可以看到我顯然已經定義了函數,為什麼它不工作

class shades {

function create($name, $shades, $slug, $shortDesc, $longDesc, $position){

$name = sanitize_paranoid_string($name);

$slug = slug($name);

$shortDesc = sanitize_sql_string($shortDesc);

$longDesc = sanitize_sql_string($longDesc);

$query = mysql_query("INSERT INTO products (type, name, slug, shortDesc, htmlDesc, position)VALUES('shades','$name','$slug','$shortDesc','$longDesc','$position')")or die(mysql_error());

$ID = mysql_insert_id();

assign($shades, $ID);

if($query) {return true;}

else {return false;};

}

function delassign($toID){

mysql_query("DELETE FROM assign WHERE type='shades' AND toID='$toID'")or die(mysql_error());

}

function assign($shades, $toID)

{

foreach($shades as $shade)

{

$result = mysql_query("INSERT INTO assign(type, typeID, toID)VALUES('shades','$shade','$toID')")or die(mysql_error());

if($result){echo "Added!";}

else{echo"Not Added!";}

};

}

}