php - INSERT & CREATE TABLE doesn't seem to be working -


i'm experiencing problems.

basically, use pdo , want create table , insert stuff table.

i've tried searching solutions, doesn't seem working.

please take @ this:

public function install() {     global $con;      $sql = "create table if not exists users         (id int(11) primary_key,           uname varchar(30) ,           pass varchar (40))";      $sq = $con->query($sql);      if ($sq)     {         echo "table created!";     }     else     {         $this->errors[] = 'error creating table: users';     }      $sql_code = "insert users (         `uname`,          `pass` ) values(          `$this->username`,         `$this->password`         )";      $sq1 = $con->query($sql_code);      if ($sql_code)     {         echo "successfull!";     }     else     {        echo "error creating admin user!";     } } 

note: database connection set in file called config.php , i've included config.php file code.

well, there plenty of things going on, perhaps @ same time.

maybe database connection failing (i'd recommend passing connection $con reference function install rather using global keyword).

maybe don't have enough rights create table in database.

also not binding parameters, correct way it:

$sql_code = "     insert users (         uname,         pass     )     values (         :username,         :password     );     ";  $sq1 = $con->prepare($sql_code); $sq1->bindparam(':username', $username); $sq1->bindparam(':password', $password); $sq1->query($sql_code); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -