Cannot insert into SQLite database via php PDO

Help with pls find out what is wrong .... (I am testing the db connection in order)

<?php
$user_name=$_POST['user_name'];
$password=$_POST['password'];

$dbh=new PDO('sqlite:./db/user.db') or die("fail to connect db");

try{
 $stmt = $dbh->prepare("INSERT INTO user_info VALUES (?, ?)");
 $stmt->bindParam(1, $a);
 $stmt->bindParam(2, $b);
 $a=$user_name;
 $b=$password;
 $stmt->execute();
}
catch(PDOException $e) {echo $e->getMessage();}

?>
+3
source share
4 answers

@DerrickCoetzee . , some. , , , . , , , , , php. php , apache "nobody" root, .

, php, , . , , , , @Derrick, sqlite db, , . , . , php , root , MySQL, .

, db .


:

! php sqlite, . ( ) - sqlite, . , , false, execute if.

, - , 100%, . , , .

, . . (user.db) (./db) .

, :

chmod 777 ./db
chmod 766 ./db/user.db

, , . , , .

+5

$a $b, .

:

 $stmt->bindParam(1, $user_name);
 $stmt->bindParam(2, $password);
0

$a $b .

$user_name=$_POST['user_name'];
$password=$_POST['password'];
$a=$user_name;
$b=$password;

try{
 $stmt = $dbh->prepare("INSERT INTO user_info (user_name, password) VALUES (?, ?)");
 $stmt->bindParam(1, $a);
 $stmt->bindParam(2, $b);
 $stmt->execute();
}
catch(PDOException $e) {echo $e->getMessage();}

$user_name $password. $a $b.

[Edited SQL to include column names]

0
source

try like this:

$stmt = $dbh->prepare("INSERT INTO user_info VALUES (?, ?)");
$data = array($user_name, $password);
$stmt->execute($data);
0
source

Source: https://habr.com/ru/post/1784275/


All Articles