Answer the question
In order to leave comments, you need to log in
How to add record to SQLITE database?
I'm trying to add an entry
$webroot = $_SERVER['DOCUMENT_ROOT'];
$db = new PDO("sqlite:$webroot/db/database.db");
if($_GET['username'] == null)
exit();
$username = $_GET['username'];
$st = $db->prepare("INSERT INTO reports_blacklist_table (user_nick) VALUES (?)");
$st->execute(array($username);
Answer the question
In order to leave comments, you need to log in
1. And who will write the brackets correctly? You have a php error: (one parenthesis is missing):
2. Read about error handling in php - php.net/manual/ru/pdo.error-handling.php
$webroot = $_SERVER['DOCUMENT_ROOT'];
try
{
$db = new PDO("sqlite:$webroot/db/database.db");
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$username = $_GET['username'];
if ( empty($username) )
{
throw new \Exception("User name is empty");
}
$st = $db->prepare("INSERT INTO reports_blacklist_table (user_nick) VALUES (?)");
$st->execute([$username]);
}
catch( \Exception $e )
{
var_dump($e->getMessage());
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question