Asked  7 Months ago    Answers:  5   Viewed   39 times

this is the error Fatal error: Call to undefined function assign(
this is the code, as you can see i obviously have defined the function so why is it not working

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!";}



You dont have a function named assign(), but a method with this name. PHP is not Java and in PHP you have to make clear, if you want to call a function


or a method


In your case the call to the function resides inside another method. $this always refers to the object, in which a method exists, itself.

Wednesday, March 31, 2021
answered 7 Months ago

you have to use the SQL Server native driver for php at first place, then you can do something like:

$serverName = ", 1433";

$connectionOptions = array("Database" => "sampleInit", 

                           "UID" => "sampleUsr@sample",

                           "PWD" => "samplePass",

                           "MultipleActiveResultSets" => false);

$conn = sqlsrv_connect($serverName, $connectionOptions);

if($conn === false)


     die(print_r(sqlsrv_errors(), true));


You can read more on PHP and SQL Azure at following blog post:

Wednesday, March 31, 2021
answered 7 Months ago
function __construct(){   $ingObject = new Ingredient();   }

ought to be

function __construct(){   $this->ingObject = new Ingredient();   }

In the first case you're setting a local variable, not a field, so it remains null. Then on the validateData you invoke a method on a null variable.

I'm assuming you snipped some code, because your Ingredient class doesn't make sense (there's a $validate variable there that isn't defined).

Wednesday, March 31, 2021
answered 7 Months ago

Make sure you're including the file you think you are. If your index.php page looks exactly like you've stated, then it won't return anything.

If you want to link to the same location from anywhere on the site without worrying about relative locations, then at the beginning of the file, put:


And it should work fine, provided your file would be located at

Monday, August 23, 2021
answered 2 Months ago

Yes, it is possible, that is know as variable functions, have a look at this.

Example from PHP's official site:

class Foo
    function Variable()
        $name = 'Bar';
        $this->$name(); // This calls the Bar() method

    function Bar()
        echo "This is Bar";

$foo = new Foo();
$funcname = "Variable";
$foo->$funcname();  // This calls $foo->Variable()


In your case, make sure that the function do_the_thing exists. Also note that you are storing the return value of the function:

$req = $class->$function_name();

Try to see what the variable $req contains. For example this should give you info:

print_r($req); // or simple echo as per return value of your function


Variable functions won't work with language constructs such as echo(), print(), unset(), isset(), empty(), include(), require() and the like. Utilize wrapper functions to make use of any of these constructs as variable functions.

Friday, September 24, 2021
Good Person
answered 1 Month ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :