PHP SQLite3 Query INSERT, DELETE & Redirect


PHP SQLite3 Query INSERT, DELETE & Redirect

在过去的几天里,我一直在努力理解使用php脚本作为保存按钮的简单概念。当从网页上按下按钮时,将从table A插入数据到table B,然后删除table A并重定向到我的主index.html

<?php
try {
    $db = new PDO('sqlite:/srv/db/data.db');
}
    $db->exec("INSERT * INTO Archive FROM resultstbl");
    $db->exec("DELETE * FROM resultstbl") 
 unset($db);
?>

到目前为止,我可以使用一些帮助这个PHP查询,以及任何指导。

我会这样做:

<?
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>

您可以在这里查看SQLite中插入和删除语句的语法:

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

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