PHP and SQLite3 Error in insert: SQLSTATE[HY000] [14] unable to open database file

Ok I feel like such a noob. I am trying to create a webform in which sends data to my sqlite database. I keep getting error Error in insert: SQLSTATE[HY000] [14] unable to open database file

I have tried numerous things. Here is the code for the files.

IF anyone has any idea please let me know, i will be checking this as often as possible as i need to get this correct by friday.

I’ve made sure sqlite is running and i’ve checked with php. Also went into the php file and removed the ;'s
Thank you

index.html

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” />
<meta name=“description” content=“Created by: Jonathan Brainard” />
<title>Main Page</title>
<style type=“text/css”>
<!–
.style1 {
font-family: “Times New Roman”, Times, serif;
font-size: 16px;
color: #003E34;
}
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 16px;
color: #000000;
}
body {
background-color: #FFFFFF;
}
–>
</style>
<link href=“color.css” rel=“stylesheet” type=“text/css” />
<style type=“text/css”>
<!–
a:link {
color: #FF0000;
}
a:visited {
color: #0000FF;
}
.style4 {
font-size: 16px;
font-family: “Times New Roman”, Times, serif;
}
.style5 {
font-size: 12px
}
.style6 {
font-size: 18px;
font-weight: bold;
}
.style15 {color: #000000; font-family: “Times New Roman”, Times, serif; font-size: 15px; }
.style16 {
font-family: “Times New Roman”, Times, serif;
font-size: 18px;
font-weight: bold;
}
.style18 {
font-size: 36px
}
.style21 {font-size: 24px; font-family: “Times New Roman”, Times, serif;}
.style23 {font-size: 26px}
.style24 {font-size: 14px}
–>
</style>
<script src=“AC_RunActiveContent.js” type=“text/javascript”></script>
</head>
<body>

<div class=“style16”>
<div align=“left” class=“style18”>
<div align=“center”>Admissions Inquiry Form</div>
</div>
</div>
<h3 align=“center”>Please fill out the following information.</h3>
<div align=“left” class=“style21 style23”></div>
<p align=“center”></p>
<form action=‘save.php’ method=‘post’>
<div align=“left” class=“style1”>

          &lt;div align="center"&gt;
            &lt;table width="367" border="0" align="center" cellpadding="1" cellspacing="1"&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;span class="style15"&gt;Last Name:&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;span class="style15"&gt;
        &lt;label&gt;
        &lt;input name="lname" type="text" id="lname" size="30" maxlength="60" /&gt;
        &lt;/label&gt;
        &lt;/span&gt;&lt;/td&gt;
      &lt;/tr&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;p class="style15"&gt;First Name:&lt;/p&gt;          &lt;/td&gt;
        &lt;td&gt;&lt;span class="style15"&gt;
        &lt;label&gt;
        &lt;input name="fname" type="text" id="fname" size="30" maxlength="60" /&gt;
        &lt;/label&gt;
        &lt;/span&gt;&lt;/td&gt;
      &lt;/tr&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;span class="style15"&gt;Middle Intial:&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;span class="style15"&gt;
        &lt;label&gt;
        &lt;input name="mname" type="text" id="mname" size="5" maxlength="1" /&gt;
        &lt;/label&gt;
        &lt;/span&gt;&lt;/td&gt;
      &lt;/tr&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;span class="style15"&gt;Street Line 1:&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;span class="style15"&gt;
        &lt;label&gt;
        &lt;input name="street1" type="text" id="street1" size="30" maxlength="30" /&gt;
        &lt;/label&gt;
        &lt;/span&gt;&lt;/td&gt;
      &lt;/tr&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;span class="style15"&gt;Street Line 2:&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;span class="style15"&gt;
        &lt;label&gt;
        &lt;input name="street2" type="text" id="street2" size="30" maxlength="30" /&gt;
        &lt;/label&gt;
        &lt;/span&gt;&lt;/td&gt;
      &lt;/tr&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;span class="style15"&gt;City:&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;span class="style15"&gt;
        &lt;label&gt;
        &lt;input name="city" type="text" id="city" size="30" maxlength="20" /&gt;
        &lt;/label&gt;
        &lt;/span&gt;&lt;/td&gt;
      &lt;/tr&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;span class="style15"&gt;State:&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;span class="style15"&gt;
        &lt;label&gt;
        &lt;select name="state" id="state"&gt;
          &lt;option value="AL"&gt;AL&lt;/option&gt;
          &lt;option value="AK"&gt;AK&lt;/option&gt;
          &lt;option value="AS"&gt;AS&lt;/option&gt;
          &lt;option value="AZ"&gt;AZ&lt;/option&gt;
          &lt;option value="AR"&gt;AR&lt;/option&gt;
          &lt;option value="CA"&gt;CA&lt;/option&gt;
          &lt;option value="CO"&gt;CO&lt;/option&gt;
          &lt;option value="CT"&gt;CT&lt;/option&gt;
          &lt;option value="DE"&gt;DE&lt;/option&gt;
          &lt;option value="DC"&gt;DC&lt;/option&gt;
          &lt;option value="FM"&gt;FM&lt;/option&gt;
          &lt;option value="FL"&gt;FL&lt;/option&gt;
          &lt;option value="GA"&gt;GA&lt;/option&gt;
          &lt;option value="GU"&gt;GU&lt;/option&gt;
          &lt;option value="HI"&gt;HI&lt;/option&gt;
          &lt;option value="ID"&gt;ID&lt;/option&gt;
          &lt;option value="IL"&gt;IL&lt;/option&gt;
          &lt;option value="IN"&gt;IN&lt;/option&gt;
          &lt;option value="IA"&gt;IA&lt;/option&gt;
          &lt;option value="KS"&gt;KS&lt;/option&gt;
          &lt;option value="KY"&gt;KY&lt;/option&gt;
          &lt;option value="LA"&gt;LA&lt;/option&gt;
          &lt;option value="ME"&gt;ME&lt;/option&gt;
          &lt;option value="MH"&gt;MH&lt;/option&gt;
          &lt;option value="MD"&gt;MD&lt;/option&gt;
          &lt;option value="MA"&gt;MA&lt;/option&gt;
          &lt;option value="MI"&gt;MI&lt;/option&gt;
          &lt;option value="MN"&gt;MN&lt;/option&gt;
          &lt;option value="MS"&gt;MS&lt;/option&gt;
          &lt;option value="MO"&gt;MO&lt;/option&gt;
          &lt;option value="MT"&gt;MT&lt;/option&gt;
          &lt;option value="NE"&gt;NE&lt;/option&gt;
          &lt;option value="NV"&gt;NV&lt;/option&gt;
          &lt;option value="NH"&gt;NH&lt;/option&gt;
          &lt;option value="NJ"&gt;NJ&lt;/option&gt;
          &lt;option value="NM"&gt;NM&lt;/option&gt;
          &lt;option value="NY"&gt;NY&lt;/option&gt;
          &lt;option value="NC"&gt;NC&lt;/option&gt;
          &lt;option value="ND"&gt;ND&lt;/option&gt;
          &lt;option value="MP"&gt;MP&lt;/option&gt;
          &lt;option value="OH"&gt;OH&lt;/option&gt;
          &lt;option value="OK"&gt;OK&lt;/option&gt;
          &lt;option value="OR"&gt;OR&lt;/option&gt;
          &lt;option value="PW"&gt;PW&lt;/option&gt;
          &lt;option value="PA"&gt;PA&lt;/option&gt;
          &lt;option value="PR"&gt;PR&lt;/option&gt;
          &lt;option value="RI"&gt;RI&lt;/option&gt;
          &lt;option value="SC"&gt;SC&lt;/option&gt;
          &lt;option value="SD"&gt;SD&lt;/option&gt;
          &lt;option value="TN"&gt;TN&lt;/option&gt;
          &lt;option value="TX"&gt;TX&lt;/option&gt;
          &lt;option value="UT"&gt;UT&lt;/option&gt;
          &lt;option value="VT"&gt;VT&lt;/option&gt;
          &lt;option value="VI"&gt;VI&lt;/option&gt;
          &lt;option value="VA"&gt;VA&lt;/option&gt;
          &lt;option value="WA"&gt;WA&lt;/option&gt;
          &lt;option value="WV"&gt;WV&lt;/option&gt;
          &lt;option value="WI"&gt;WI&lt;/option&gt;
          &lt;option value="WY"&gt;WY&lt;/option&gt;
        &lt;/select&gt;
        &lt;/label&gt;
        &lt;/span&gt;&lt;/td&gt;
      &lt;/tr&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;span class="style15"&gt;Zip:&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;span class="style15"&gt;
        &lt;label&gt;
        &lt;input name="zip" type="text" id="zip" size="30" maxlength="5" /&gt;
        &lt;/label&gt;
        &lt;/span&gt;&lt;/td&gt;
      &lt;/tr&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;span class="style15"&gt;Area Code:&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;span class="style15"&gt;
        &lt;label&gt;
        &lt;input name="areacode" type="text" id="areacode" size="30" maxlength="3" /&gt;
        &lt;/label&gt;
        &lt;/span&gt;&lt;/td&gt;
      &lt;/tr&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;span class="style15"&gt;Phone Number:&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;span class="style15"&gt;
        &lt;label&gt;
        &lt;input name="phone" type="text" id="phone" size="30" maxlength="7" /&gt;
        &lt;/label&gt;
        &lt;/span&gt;&lt;/td&gt;
      &lt;/tr&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;span class="style15"&gt;E-mail:&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;span class="style15"&gt;
        &lt;label&gt;
        &lt;input name="email" type="text" id="email" size="30" maxlength="60" /&gt;
        &lt;/label&gt;
        &lt;/span&gt;&lt;/td&gt;
      &lt;/tr&gt;
              &lt;tr&gt;
                &lt;td class="style15"&gt;Birthday: &lt;span class="style24"&gt;DDMMYYYY&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;span class="style15"&gt;
        &lt;label&gt;
        &lt;input name="bday" type="text" id="bday" size="30" maxlength="10" /&gt;
        &lt;/label&gt;
        &lt;/span&gt;&lt;/td&gt;
      &lt;/tr&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;span class="style15"&gt;Gender:&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;span class="style15"&gt;
        &lt;label&gt;
        &lt;select name="gender" id="gender"&gt;
          &lt;option value="M" selected="selected"&gt;Male&lt;/option&gt;
          &lt;option value="F"&gt;Female&lt;/option&gt;
        &lt;/select&gt;
        &lt;/label&gt;
        &lt;/span&gt;&lt;/td&gt;
      &lt;/tr&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;span class="style15"&gt;Highschool CEEB Code:&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;input name="ceeb" type="text" id="ceeb" size="30" maxlength="16" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;span class="style15"&gt;Highschool Graduation Year:&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;input name="gradyear" type="text" id="gradyear" size="30" maxlength="4" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;span class="style15"&gt;Major Code:&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;input name="major" type="text" id="major" size="30" maxlength="4" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;span class="style15"&gt;Interest Code:&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;input name="interest" type="text" id="interest" size="30" maxlength="2" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;span class="style15"&gt;Inquiry Type:&lt;/span&gt;&lt;/td&gt;
        &lt;td&gt;&lt;span class="style15"&gt;
        &lt;select name="inquiry" id="inquiry"&gt;
          &lt;option value="CN"&gt;College Night&lt;/option&gt;
          &lt;option value="HS"&gt;High School&lt;/option&gt;
          &lt;option value="O"&gt;Other&lt;/option&gt;
        &lt;/select&gt;
        &lt;/span&gt;&lt;/td&gt;
      &lt;/tr&gt;
            &lt;/table&gt;
&lt;/div&gt;
&lt;p align="center"&gt;&lt;strong&gt;
  &lt;input name="Submit" type="Submit" id="Submit" value="Submit" /&gt;
&lt;/strong&gt;&lt;/p&gt;
&lt;div class="style6"&gt;&lt;/div&gt;

</div>
</form>

<p align=“center”> </p>
<p align=“center”><span class=“style4”>If you have any questions please contact the <a href=“mailto:brainajw@alfredstate.edu”>Web Master</a></span></p>

save.php

<style type=“text/css”>
<!–
.insert {font-family: “Times New Roman”, Times, serif;
color: #000000;
background-color: #FFFFFF;
}
–>
</style>
<h1>
<center>
<p><b>Thank you!</b></p>
</center>
</h1>
<h3>
<center>
<p class=“insert”>You may exit your browser, or click <a href=“index.html” target=“_parent”>here</a> to return.</p>
</center>
</h3>
<?php
ini_set(“display_errors”, true);

// if form submitted
// attempt database connection

//$db=‘admission.db’;
//$sqlite= new SQLiteDatabase($db, 0666);

// check input making sure required fields have data
$lname= !empty($_POST[‘lname’]) ? sqlite_escape_string($_POST[‘lname’]) : die(‘ERROR: Last name is required’);
$fname= !empty($_POST[‘fname’]) ? sqlite_escape_string($_POST[‘fname’]) : die(‘ERROR: First name is required’);
$mname= !empty($_POST[‘mname’]) ? sqlite_escape_string($_POST[‘mname’]) : die(‘ERROR: Middle intial is required’);
$street1= !empty($_POST[‘street1’]) ? sqlite_escape_string($_POST[‘street1’]) : die(‘ERROR: Street line 1 is required’);
$street2= $_POST[‘street2’]; //not required
$city= !empty($_POST[‘city’]) ? sqlite_escape_string($_POST[‘city’]) : die(‘ERROR: City is required’);
$state= !empty($_POST[‘state’]) ? sqlite_escape_string($_POST[‘state’]) : die(‘ERROR: State is required’);
$zip= !empty($_POST[‘zip’]) ? sqlite_escape_string($_POST[‘zip’]) : die(‘ERROR: Zip Code is required’);
$areacode= !empty($_POST[‘areacode’]) ? sqlite_escape_string($_POST[‘areacode’]) : die(‘ERROR: Area code is required’);
$phone= !empty($_POST[‘phone’]) ? sqlite_escape_string($_POST[‘phone’]) : die(‘ERROR: Phone # is required’);
$email= !empty($_POST[‘email’]) ? sqlite_escape_string($_POST[‘email’]) : die(‘ERROR: Email required’);
$bday= !empty($_POST[‘bday’]) ? sqlite_escape_string($_POST[‘bday’]) : die(‘ERROR: Birthday is required’);
$gender= !empty($_POST[‘gender’]) ? sqlite_escape_string($_POST[‘gender’]) : die(‘ERROR: Gender is required’);
$ceeb= !empty($_POST[‘ceeb’]) ? sqlite_escape_string($_POST[‘ceeb’]) : die(‘ERROR: Highschool CEEB Code is required’);
$gradyear= !empty($_POST[‘gradyear’]) ? sqlite_escape_string($_POST[‘gradyear’]) : die(‘ERROR: Highschool Graduation Year is required’);
$major= !empty($_POST[‘major’]) ? sqlite_escape_string($_POST[‘major’]) : die(‘ERROR: Major Code is required’);
$interest= !empty($_POST[‘interest’]) ? sqlite_escape_string($_POST[‘interest’]) : die(‘ERROR: Interest Code is required’);
$inquiry= !empty($_POST[‘inquiry’]) ? sqlite_escape_string($_POST[‘inquiry’]) : die(‘ERROR: Inquiry Type is required’);

try
{

$dbh = new PDO('sqlite:"C:\\wamp\\www\\admissions.db"');

$sql = "INSERT INTO students VALUES  ('','$lname','$fname','$mname','$street1','$street2','$city','$state','$zip','$areacode','$phone','$email','$bday','$gender','$ceeb','$gradyear','$major','$interest','$inquiry')";
$dbh-&gt;query($sql);
echo "Thank You";

}
catch(PDOException $e)
{
echo "Error in insert: " . $e->getMessage();
}
/*** close the database connection ***/
$dbh = null;

//$sql = “INSERT INTO students VALUES (‘’,‘$lname’,‘$fname’,‘$mname’,‘$street1’,‘$street2’,‘$city’,‘$state’,‘$zip’,‘$areacode’,‘$phone’,‘$email’,‘$bday’,‘$gender’,‘$ceeb’,‘$gradyear’,‘$major’,‘$interest’,‘$inquiry’)”;

//if ($sqlite->queryExec($sql) == true) {
//echo ‘<div id=“message”>Data recorded successfully.</div>’;
//} else {
//echo "ERROR: Could not execute $sql. " . sqlite_error_string($sqlite->lastError());
//}
// close connection
//unset($sqlite);
?>

http://www.php.net/manual/en/ref.pdo-sqlite.connection.php

You have more quotes than needed.

$dbh = new PDO(‘sqlite:C:\wamp\www\admission.db’);

$sql = "INSERT INTO students VALUES  ('','$lname','$fname','$mname','$street1','$street2','$city','$state','$zip','$areacode','$phone','$email','$bday','$gender','$ceeb','$gradyear','$major','$interest','$inquiry')";
$dbh-&gt;query($sql);
echo "Thank You";

I removed the quotes out of there and its saying thank you and not showing any errors, but im not seeing the data in sqlite when i load it up.

:x

Ok well i got it up and working after a few tweaks. im calling in my code admission.db but infact sqlite is calling admission so i just had to use admission for both.

The only problem i am running into is with setting my ID as a primary key. When i do this, it is only showing my first entry and everything else is being avoided and not saved. When i do id integer primary key auto increment it doesnt save anything to the database.

any suggestions?

The empty string value looks suspect, if that’s supposed to correspond to the value of the auto inc primary key. You can use NULL, but personally I’m not a big fan of sql statements that rely on the column order. Use the explicitly named column names styleinsert into foo (fname, lname, …) values (‘john’, ‘doe’, …). You can just completely leave out the column with auto increment when you use this style.

Anyway, I’m gonna recommend you use a separate tool to interface with sqlite, to make it easy to test your sql statements. Try sqlitemanager, it’s a firefox plugin. It’s much faster to test using the gui.