How can I insert posted data into the database?

I am trying to insert data from a form into my database in an object-oriented fashion, but the data just isn't inserted. Why not?

  • 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();

  • Answer:

    What's the output of mysql_error()? Have you called mysqldb() ? Do you have a connection? Do you have autocommit enabled in your DB/connection?

Lucian Nutiu at Quora Visit the source

Was this solution helpful to you?

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.