php sqlite not storing data

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

Answers


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).


Need Your Help

JQuery Stack of Cards

javascript jquery html animation

I have a stack of cards. They are stacked so each one has about a centimetre at the bottom visible. What I want, is when a card is clicked it moves to the right, then gets sorted to the top and mov...

Increasing page load time

javascript code-organization load-time

I have a javascript source code file which is about 32kb, and has javascript code arranged in modules.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.