I’m trying to insert data into a database that I have on my server.
To connect to my database I have the following code:
<?php
$host = "/homes/49/jc192699/public_html/dbase/";
$database = "EduPro.db";
$dbhandle = new PDO("sqlite:".$host.$database);
try {
$dbhandle = new PDO("sqlite:".$host.$database);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
?>
and this all works fine! I have included this into my code so that is not the issue.
Here is my code for inserting data into the database:
<?php
$sql = "INSERT INTO USERS (`userName`, `password`) VALUES (`test, `testy`)";
if ( $fetched = $dbhandle->query($sql)){
$fetched->execute(PDO::FETCH_BOTH);
echo "Success!";
}
else {
echo "Fail.";
}
?>
It is not inserting the data into the database for some reason. I know that the SQL statement is 100% correct as I have tested it elsewhere.
Can anyone help me?
you are opening two database connection. change your code to
you should not use backquote instead using single quote in your query. and also column should not have any quotes.
to fetch the records you need to use this
learn more about PDO here http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/