PHP SQLite3查询插入、删除和重定向

PHP SQLite3查询插入、删除和重定向,php,sqlite,Php,Sqlite,在过去的几天里,我一直在琢磨使用php脚本作为保存按钮的简单概念。当从网页中按下该按钮时,会将数据从表a插入表B,然后删除表a并重定向回my main index.html 到目前为止,我可以在这个PHP查询中使用一些帮助以及任何指导。我会这样做: <? if(isset($_POST['but1'])) // this checks if the button is clicked { $db = new PDO('sqlite:/srv/db/data.db'); // I

在过去的几天里,我一直在琢磨使用php脚本作为保存按钮的简单概念。当从网页中按下该按钮时,会将数据从表a插入表B,然后删除表a并重定向回my main index.html


到目前为止,我可以在这个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的insert和delete语句的语法:


非常感谢你,我请求你帮我把头发拔出来。不过,还有一个简短的补充问题。。。。该脚本按照我的要求循环并删除我的表的内容,但它没有将resultstbl的内容复制到存档中。这可能是因为存档中有一个键,而resultstbl中有一个不匹配的列吗?当然,表必须具有完全相同的结构,才能从一个直接选择到另一个。要解决您现在遇到的问题,您应该这样做:将字段1、字段2、字段3插入存档从ResultsTbl中选择字段1、字段2、字段3只需一个脚注,上面我的问题的答案是:是的,两个字段都需要具有完全相同的字段,才能使用上述插入语法。
<?

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>