无法插入DB PHP

时间:2011-06-24 20:06:06

标签: php mysql arrays

我在尝试将值插入数据库时​​遇到问题,'randomkey'插入为0 ...

在一页上我有......

  if($usersClass->register($_POST['produgg_username'], md5($_POST['produgg_password']), $_POST['produgg_email'], $randomkey))   

和插入页面......

public function register($username, $password, $email)
    {
    $rs = mysql_query("INSERT INTO `$this->usersTable` (`username`, `password`, `email`, `randomkey` ) 
                    VALUES 
                    ('".mysql_real_escape_string($username)."',
                    '".mysql_real_escape_string($password)."',
                    '".mysql_real_escape_string($email)."',
                    '".$randomkey."'
                    )");

    if($rs) {
        return mysql_insert_id();
    }else{
        return false;
    }       

}

2 个答案:

答案 0 :(得分:3)

您忘记将其包含在已接受的参数中:

public function register($username, $password, $email)

应该是:

public function register($username, $password, $email, $randomkey)

答案 1 :(得分:1)

public function register($username, $password, $email, $randomkey)
    {
    $rs = mysql_query("INSERT INTO `$this->usersTable` (`username`, `password`, `email`, `randomkey` ) 
                    VALUES 
                    ('".mysql_real_escape_string($username)."',
                    '".mysql_real_escape_string($password)."',
                    '".mysql_real_escape_string($email)."',
                    '".$randomkey."'
                    )");

    if($rs) {
        return mysql_insert_id();
    }else{
        return false;
    }       

}