0

I am trying out sqlite with php. On the server when I execute the command sqlite3, it shows the version and help option suggesting that sqlite is installed there. My folder structure is like this: /username/public_html/
Now I created a db called "chatuser.db" with a table "Users" and two columns "Username" and "Password" using sqlite3 command at /username I then copied the db using WinSCP to my windows folder and then copied it back to the server here: /username/public_html/ (I know it is not a good idea to keep db file in public_html, but am just trying out an example). Now I have the following php file:
add.php:

<?php

$password = $_POST['password'];
$username = $_POST['username'];

$name_es = sqlite_escape_string($username);
$password_es = sqlite_escape_string($password);

if (!empty($username)) {

   $dbhandle = sqlite_open('chatuser.db', 0666, $error);

   if (!$dbhandle) die ($error);

   $stm = "INSERT INTO Users(Username, Password) VALUES('$name_es', '$password_es')";
   $ok = sqlite_exec($dbhandle, $stm, $error);

   if (!$ok) die("Error: $error");  
   else echo "Success";
}
?>

index.html:

<html>
<head>
<title>Login Trial</title>
</head>
<body style="font-size:12;font-family:verdana">

<form action="add.php" method="post">

<p>
Name: <input type="text" name="username"><br>
Password: <input type="text" name="password"><br><br>

</p>

<p>
<input type="submit">
</p>

</form>


</body>
</html>

On clicking the submit button, it loads add.php, but does not show me the success message nor any error message. I am not able to figure out why. As an added note, I have done chmod 777 of chatuser.db as well. This is my first introduction to sqlite, any help would be great. Thanks

[SOLVED] Found the issue, it was version mismatch. sqlite_open will not work. Alternative from this solution: Error: file is encrypted or is not a database

1 Answer 1

1

My guess would be that sqlite_open triggers a fatal error and your PHP isn't configured to show them.

Try placing one echo before the sqlite_open and one after - if only the first one is echo'ed, you know what the issue is.

You will probably want to load the sqlite3 module in PHP.

-edit-

Actually, that only applies to PHP 4, which you're probably not using anymore. Either way, make sure that your PHP outputs errors (go into php.ini and set display_errors to On and error_reporting to E_ALL).

Sign up to request clarification or add additional context in comments.

5 Comments

strangely both the echoes didn't work. I placed echo as follows: echo "testing"; $dbhandle = sqlite_open('chatuser.db', 0666, $error); if (!$dbhandle) die ($error); echo "testing again";
Whoops, sqlite_escape_string is called before the sqlite_open. Try placing the echo before that.
Yup, now the first one got called but the second one didn't. What is wrong and how do I fix it. Thanks
I strongly recommend updating your server. Sqlite support has been default since PHP 5, which was released in 2004
so, there is nothing wrong in my script or the way I have setup the db and might be a configuration issue right? Thanks

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.