2个问题:调用未定义的函数,不写入数据库

时间:2012-07-12 20:24:51

标签: php mysql

我有一个简单的课程,这会给我带来一些问题。有两个问题。我没有链接我的html文件,只是类。当我需要使用我的插入函数时,它表示它是未定义的。此外,即使我手动尝试在数据库中插入内容,也没有任何反应。

mysql_connect(“come”,“at”,“me”)或die(mysql_error());     mysql_select_db(“bro”)或die(mysql_error());

class Update
{

    public $input;

    public function assignCheck($postRequest)
    {
        if(isset($_POST[$postRequest]))
        {
            $this->input = $_POST[$postRequest];
            insert($postRequest);
            return $this->input;
        }
        else
        {
            return false;
        }
    }

    public function insert($insertRequest)
    {
        mysql_query("INSERT INTO updates (update) VALUE ($insertRequest)");
    }
}

2 个答案:

答案 0 :(得分:3)

为了调用您的插入函数,您必须在$this->insert($postRequest)函数的if语句中使用assignCheck

答案 1 :(得分:0)

在一个类中,您使用伪变量

调用方法
$this

所以:

if(isset($_POST[$postRequest]))
{
    $this->input = $_POST[$postRequest];
    $this->insert($postRequest);
    return $this->input;
}