0

I have a register page on my site which feeds POST data into a PHP file, which then INSERTs it into a database. The problem is, the query:

class DB extends SQLite3{
    function __construct(){
            $this->open('db/userpass.db');
    }
}

$db = new DB();

$db->query("INSERT INTO userpass VALUES($user, $encrypted_pass)");

isn't querying. Picture book is here: https://i.sstatic.net/GnxFF.jpg

You can see my problem in the album. However, I most definitely query'd.

2
  • 1
    You don't check the result of $db->query. Commented Nov 10, 2013 at 22:08
  • @MarcelKorpel What do I do then? Commented Nov 10, 2013 at 22:48

1 Answer 1

2

SELECT performs a query, INSERT doesn't. exec must be used instead.

However, because you are merging data in your command, you better use statements:

$stmt = $db->prepare('INSERT INTO userpass VALUES(:user, :encrypted_pass)');
$stmt->bindValue(':user', $user);
$stmt->bindValue(':encrypted_pass', $encrypted_pass);
if ($stmt->execute()==FALSE) {
    //handle errors here!
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for clarifying, I wasn't aware. query = read data, exec = write data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.