0

I'm getting this

-> [Tue Sep 10 10:42:46 2013] [error] [client 127.0.0.1] PHP Warning: SQLite3::exec(): unable to open database file in /var/www/ET/insert.php on line 21, referer: http://localhost/ET/

I changed the owner of the DB file (et.sqlite3) to www-data and now this is what I'm getting. Before I changed the owner I was getting an "unable to write to DB" error. Code is below, any ideas? Thanks.

<?php

echo "<html>";
echo "<head>";
echo "</head>";
echo "<body>";

$db = new SQLite3('./et.sqlite3', SQLITE3_OPEN_READWRITE);

if(!$db)
{
    echo "Could not open/access DB";
}
else
{
    // get variable from html form
    $fName = $_POST['fname'];
    $lName = $_POST['lname'];
    $email = $_POST['email'];

    $db->exec("INSERT INTO customers VALUES('$fName', '$lName', '$email')");
}

echo "</body>";
echo "</html>";

?>
3
Contributors
6
Replies
18
Views
4 Years
Discussion Span
Last Post by lewashby
0

Check if the file and also the directory containing the database, have read and write permissions.

0

This is the containing directory:
drwxr-xr-x 2 root root 4096 Sep 10 12:05 ET

Here is the file:
-rw-r--r-- 1 www-data root 2048 Aug 31 15:58 et.sqlite3
-rw-r--r-- 1 root root 410 Sep 10 10:35 insert.php

0

try to...
change $db->exec("INSERT INTO customers VALUES('$fName', '$lName', '$email')");
to
$db->exec("INSERT INTO customers VALUES(" . $fName . "," . $lName . "," . $email . ")");
or
$db->exec("INSERT INTO customers VALUES(" . "'" . $fName . "'" . "," . "'" . $lName . "'" . "," . "'" . $email . "'" . ")");

Edited by mark5rockzz_1: add options

0

Apache is running as root or as www-data user? It should be www-data, verify the output of:

ps -aux |grep apache

You should see the main process owned by root, the childs owned by www-data user. So, in order to work correctly, you have to change the ownership of the directory and of the files under the DocumentRoot of your website, try this:

sudo chown www-data:www-data -R /var/www/ET

With -R flag we recursively change the owners and the group of all the files inside ET directory. That should fix the problem.

0

Thanks guys, I'm a little closer but still not there yet. I chagned the insert line to this:

$db->exec("INSERT INTO customers VALUES(" .$fName . "," . $lName . "," . $email .")");

And now I'm getting this in the error log when I enter the name Bailey to be written into the fName field. The column name is

[Tue Sep 10 13:36:35 2013] [error] [client 127.0.0.1] PHP Warning: SQLite3::exec(): no such column: Bailey in /var/www/ET/insert.php on line 21, referer: http://localhost/ET/

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.