For my project, these two queries don't work. The sqlite manual says to use 'qualified-table-name'
but if I do (flist.fdata) an error is returned 'no such table'. As they are below no errors are returned, but
the database table is not affected.

if (isset ($_POST['del'])) {
          $id = $_POST['id'];
          $titl=$_POST['titl'];
       $db = sqlite_open('data/flist.sqlite', 0666, $sqliteerror);
          sqlite_query($db,"DELETE FROM fdata WHERE id='$titl'");
          header('location:index.php');
          sqlite_close($db);
     }
     if (isset ($_POST['alter'])) {
          $id=$_POST['id'];
          $title=$_POST['titl'];
          $art=$_POST['art'];
          $cat=$_POST['cat'];
          $len=$_POST['len'];
          $db = sqlite_open('data/flist.sqlite', 0666, $sqliteerror);
          sqlite_query($db,"UPDATE fdata SET title='$title',artist='$art',
                            category='$cat',length='$len' WHERE id='$id'");
          header('location:index.php');                  
          sqlite_close($db);
     }

I've also tried 'main.fdata' but that doesn't work either.
Can someone point me in the right direction please, I bet I'm missing something simple!

Recommended Answers

All 7 Replies

Shouldn't you be using $id instead of $titl?

Do check if an error message is returned when opening.

There is a comment in the manual stating This function only support database of SQLite 2 or below. For SQLite 3, you must use PDO., although I'm not sure if this is true, you might want to verify.

Spotted my deliberate error! I'll correct that, but the update isn't working either,
the code is correct there. I'm using sqlite2, not got the hang of sqlite3 yet. I can't seem to find any straightforward explanation for 'qualified-table-name' anywhere,
and the sqlite manual unfortunately wasn't written with newbie silver surfers in mind!

When I used flist.fdata, an error was returned 'no such table' When I used main.fdata no errors were returned, and no changes to the database. (I remember reading somewhere that all sqlite2 databases are referred to as 'main' once opened.) Maybe I should return to mysql, but I like the challenge of learning new things, it relaxes me after work.

Ok, I've changed the first block to:

  if (isset ($_POST['del'])) {
          $id = $_POST['id'];
          $titl=$_POST['titl'];
       $db = sqlite_open('data/flist.sqlite', 0666, $sqliteerror);
       if(!$db){
         die("Database not opened".$sqliteerror);
       }else{
          sqlite_query($db,"DELETE FROM fdata WHERE id='$id'");
          echo "Record deleted";
      //    header('location:index.php');
          sqlite_close($db);
          }
     }

now, when this is run no errors are returned and the message
is displayed 'Record deleted', but it's not deleted.
This query:

   if(isset($_POST['send'])){
    $titl=$_POST['name'];
    $art=$_POST['art'];
    $cat=$_POST['cat'];
    $len=$_POST['len'];
    $uni=time('now');
    $db= sqlite_open('data/flist.sqlite',0666,$sqliteerror);
    $error='';
    if(empty($titl)){
       $error=$error."You didn't enter a title.<br>";
         }
    if(empty($art)){
       $error=$error."You didn't enter an Artist.<br>";
         }
    if(empty($cat)){
       $error=$error."You didn't enter a category.<br>";
         }
    if(empty($len)){
       $error=$error."You didn't enter a length.";
         }

       if ($error){
     echo "<div class='error'>".$error."</div>";
     }else{

       sqlite_query($db,"INSERT INTO fdata(title,artist,category,length,unix)
       VALUES('$titl','$art','$cat','$len','$uni')");

works fine, so does the search function, just the delete and update, and they are the ones that have this 'qualified-table-name' in the definition.

Oh! How embarrased am I? Still pondering this question, and going over and over the code,
I looked at the html form that ataches this script. I had missed the '=' from the input field 'name='id'', what a stupid mistake to miss!
Anyway, thanks to pritaeas i'm now adding checks to ensure things happen when they should.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.