开发者

PHP SQLite3 Query INSERT, DELETE & Redirect

I've spent the last couple of days grappling wit the simple concept of using a php script as Save button. When pressed from a webpage the button will INSERT data from table A to table B then delete table A and redirect to back to my main index.html.

<?php
try {
    $db = new PDO('sqlite:/srv/db/data.db');
}

    $db->exec("INSERT * INTO Archive FROM resultstb开发者_高级运维l");
    $db->exec("DELETE * FROM resultstbl") 
 unset($db);
?>

So far I could use some help with this PHP query, as well as any guidance.


I would do something like this:

<?

if(isset($_POST['but1'])) // this checks if the button is clicked
{
   $db = new PDO('sqlite:/srv/db/data.db');  // I assume this is working fine
   $db->exec("INSERT INTO Archive SELECT * FROM resultstbl"); // tables must be equivalent in terms of fields
   $db->exec("DELETE FROM resultstbl") // You want to delete the records on this table or the table itself? This deletes the records

   header("Location: index.php?page=home"); // This will only work if you didn't output anything to the screen yet. If you displayed something it will fail
   die();

}

?>

<form action="sql.php" method="POST"> <!-- Assuming this page is sql.php -->

   <input type="submit" name="but1" value="GO!"/>
</form>

You can check the syntax for the insert and delete statments for SQLite here:

http://www.sqlite.org/lang_insert.html

http://www.sqlite.org/lang_delete.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜