我正在尝试以面向对象的方式将表单中的数据插入到我的数据库中,但只是没有插入数据。为什么不?
class users {
var $username;
var $password;
var $conection;
var $tablename = usertable;
function mysqldb() {
$this->conection = mysql_connect("local host", "root", "") or die(mysql_error());
mysql_select_db("this->tablename");
}
function insertdb() {
$query = mysql_query("INSERT INTO $this->tablename values ('', '$user', '$pass')");
$result = mysql_query($query);
if(!$result) die("Query didn't work. " . mysql_error());
}
}
$user1 = new users;
$user1->username = $_POST["user"];
$user1->password = $_POST["pass"];
$user1->insertdb();