sqlite更新表查看插入数据库的新结果

时间:2018-01-11 01:29:49

标签: php

我有一个数据库,我已经插入了新的条目。我现在卡住尝试将textarea输入存储为新的$ var,将其插入表中,然后更新新的表结果,全部在提交按钮上点击事件。到目前为止这是我的代码。循环适用于先前输入的条目。它不会因某种原因而更新。

<?php
session_start();

$db=sqlite_open("MainDB.db");

$result=sqlite_query($db,"SELECT * FROM stock");

$user ="tea";

$result=sqlite_query($db,"SELECT * FROM stock WHERE ProductName = '$user'");

if( sqlite_num_rows($result))
{
    echo "<table border=1>\n";
    echo "<h2>". $user. " messages"."</h2>";
    echo "</br>\n";
    echo "<th>Sender</th>\n";
}
while($row=sqlite_fetch_array($result,SQLITE_ASSOC))
{
    echo "<tr>\n";
    echo "<td>" . $row['ProductName'] . "</td>\n"; 
    echo "</tr>\n";
}

sqlite_close($db);
?>

<html>
    <body>

        <form action = "testdatabase.php" method="POST">
            <textarea rows="4" cols="50" name="message"></textarea>
            <input type="submit" value="submit">

        </form>
    </body>

</html>

然后是插入代码

<?php

 session_start();

 $db=sqlite_open("MainDB.db");

  header("location: testdatabase.php");

   $_SESSION['message'] = $_POST['message'];

   $message = $_SESSION['message']

   $result=sqlite_query($db,"SELECT * FROM stock");
   $result=sqlite_num_rows(sqlite_query($db, "SELECT * FROM stock"));

   sqlite_query($db,"INSERT INTO stock (ProductName) VALUES('$message')");


   ?>

0 个答案:

没有答案