开发者

Problem to insert in SQLite3 from PHP

开发者 https://www.devze.com 2023-03-12 11:50 出处:网络
I have strange problem on PHP page, I am trying to insert new row to table users (SQLite3) like this $id=$db->insert_user(\"\'\".$parameters[\'first_name\'].\"\'\", \"\'\".$parameters[\'last_name

I have strange problem on PHP page, I am trying to insert new row to table users (SQLite3) like this

 $id=$db->insert_user("'".$parameters['first_name']."'", "'".$parameters['last_name']."'", "'".$parameters['email']."'", "'".$parameters['username']."'", "'".$parameters['password']."'", "'".$parameters['privilege']."'");

where

     try {
            $db = new SQLite3($this->db_path);

           echo "INSERT INTO users(first_name,last_name,email,username,password,privilege) VALUES('$first_name','$last_name','$email','$username','$password','$privilege');";
           $db->query("INSERT INTO users(first_name,last_nam开发者_开发知识库e,email,username,password,privilege) VALUES('$first_name','$last_name','$email','$username','$password','$privilege');");

            $last_id = $db->lastInsertRowID();
            echo ''.$last_id;
            $db->close();
            return $last_id;
        } catch (Exception $e) {
            echo 'Exception caught: ', $e->getMessage(), "\n";
        }

INSERT INTO users(first_name,last_name,email,username,password,privilege) VALUES(''drkosh'',''drkosh'',''drkosh'',''drkosh'',''drkosh'',''ignore'');

result from echo is

INSERT INTO users(first_name,last_name,email,username,password,privilege) VALUES(''drkosh'',''drkosh'',''drkosh'',''drkosh'',''drkosh'',''ignore'');

Error message is strange, it says in line 35, but 35 is in switch and I never pass through 35, have breaks. Does anybody have some clue what is wrong ? (all columns are ok and table name)


look at the sql query, there is ''drkosh'', but there should only be 'drkosh'

INSERT INTO users(first_name,last_name,email,username,password,privilege) VALUES(''drkosh'',''drkosh'',''drkosh'',''drkosh'',''drkosh'',''ignore'');

try this:

$id=$db->insert_user($parameters['first_name'], $parameters['last_name'], $parameters['email'], $parameters['username'], $parameters['password'], $parameters['privilege']);
0

精彩评论

暂无评论...
验证码 换一张
取 消