save data in a data base with a html form

56 views
Skip to first unread message

Ovide

unread,
Jul 28, 2016, 3:05:17 PM7/28/16
to phpliteadmin
Hello to you!
I would want to link a database that i have created with SQLite admin to a html form but
i can not do it because, i do not know the default (user name , password and the server name) of Sqlite Admin. I do not know how to connect to my base given .
I try with :
Server : localhost .
user : root ;
password : root ;
But it does not work.


Here is how I did with my scripts but no results .
$Base = "./ MyBase " ;
$Server = "localhost" ;
$User= "root" ;
$Password = "root" ;
$linkbase= mysql_connect ( $Server , $User , $Password)
// Selection of the database
$ Return = mysql_select_db ( $Base , $linkbase)


Please I will like to know everything you need to connect my html form has my database because it is so different from PhpMyAdmim I usually use .
thank you in advance

Christopher K.

unread,
Jul 28, 2016, 4:18:36 PM7/28/16
to bertra...@gmail.com, phplit...@googlegroups.com
Hey,

SQLite is not a server based Database and especially, it is not MySQL. So using mysql_connect will not work. (And mysql_connect is also deprecated for MySQL! Use MySQLi or PDO for MySQL.) Depending on what PHP extensions are installed on your server, you would need to use the SQLite3 extension or PDO to use an SQLite3 Database.

In SQLite there is no server, you only need access to the database file. So there also is no username or password. You just connect and query the database like this:

Using SQLite3:
<?php
$db 
= new SQLite3('mysqlitedb.db3');

$results $db->query('SELECT bar FROM foo');
while (
$row $results->fetchArray()) {
    
var_dump($row);
}
?>

mysqlitedb.db3 is the name of your database file (assuming it is in the same directory, if not, add the path).
Source: http://php.net/manual/en/sqlite3.query.php

Or using PDO:

<?php
$conn = new PDO("sqlite:mysqlitedb.db3");
$sql 'SELECT name, color, calories FROM fruit ORDER BY name';
foreach ($conn->query($sql) as $row) {
    print $row['name'] . "\t";
    print $row['color'] . "\t";
    print $row['calories'] . "\n";
}
?>

Sources: http://php.net/manual/en/ref.pdo-sqlite.connection.php
http://php.net/manual/en/pdo.construct.php
http://php.net/manual/en/pdo.query.php


I hope this helps you to get stared.

Greetings,
Christopher

Ovide .

unread,
Jul 28, 2016, 8:59:47 PM7/28/16
to Christopher K., phplit...@googlegroups.com
If I want to insert for example , a name in a table ( called "data" ) contained in a database ( called 'database' ) . In the user-name field. How do I do? Please I will like to have the complete procedure .
Thanks.

Christopher Kramer

unread,
Jul 29, 2016, 4:17:41 AM7/29/16
to phpliteadmin


Am Freitag, 29. Juli 2016 02:59:47 UTC+2 schrieb Ovide:
If I want to insert for example , a name in a table ( called "data" ) contained in a database ( called 'database' ) . In the user-name field. How do I do? Please I will like to have the complete procedure .
Thanks.
 
First, this mailing list is not for SQlite or PHP questions, it is for phpLiteAdmin. Your problems are not related to phpLiteAdmin, so you are asking at the wrong place. Maybe post your questions at stack overflow for example. Also, before asking someone, first please read the manuals, especially if somebody provides you links to it. And search the web first. Its not like there are no tutorials on SQLite and PHP.

One last answer:

Using SQLite3, you insert into an SQLite db like this (see the manual on exec):

<?php
$db 
= new SQLite3('database');
$results $db->exec('INSERT INTO data ("user-name") VALUES(\'bob\')');
?>

 

Ovide .

unread,
Jul 29, 2016, 7:55:48 AM7/29/16
to phplit...@googlegroups.com
Thank you! Thank you very much.
I'm happy. Thanks

--
You received this message because you are subscribed to a topic in the Google Groups "phpliteadmin" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/phpliteadmin/6mXqtt8U5lg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to phpliteadmin...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jan Zumwalt

unread,
Jul 29, 2016, 10:50:11 PM7/29/16
to phpliteadmin
I also wanted db access from html. So... I'll share extensive research I did on my own on this subject.
The short answer is the only way to do this is using client side JS browser  hidden info that can not be modified or backed up.
Google Chrome and Firefox experimented with the capability and other browsers immediately blocked the capability - they eventually abandon the feature.
The only reasonable way to access DB info is server side using PHP and sqlite.

I think it is a sever flaw to ignore db capability in html, but the html and JS consortium apparently see things different.
Reply all
Reply to author
Forward
0 new messages