从html表单发布时,它可以找到我的操作文件

时间:2015-02-07 14:41:41

标签: php html

基本上我有一个html表单,其中

action="newlist.php"

并且它与php文件在同一目录中,每当我提交它时,我都会收到错误,

Not Found

The requested URL /~u1418925/cs139/‘newlist.php’ was not found on this server.

可能导致这种情况,我所有php文件的权限都是chmod a + rx * .php。提前谢谢。

对不起,我在文件周围有单引号,但现在我已经改变了它做了双倍似乎找到了文件,但文件没有将这些值插入数据库,所有代码都在

表格代码:

<form action="newlist.php" method="POST">
    List Name:<br>
    <input type="text" name='list_name'><br><br>
    List Importance(0-5):<br>
    <input type="text" name=‘list_importance’><br><br>
    <input type="submit" value="Create List">
</form>

newlist.php代码:

<?php
   require 'database.php';
   $listname = $_POST["list_name"];
   $listimportance = $_POST["list_importance"];

   $db = new Database();
   $db->exec("INSERT INTO lists VALUES(NULL, 1, $listname, NA, $listimportance, 0);");

?>

Schema.sql代码:

DROP TABLE users;
CREATE TABLE users(id integer primary key, username varchar(30), password varchar(30), email varchar(50), receive_email blob, gender varchar(6));

DROP TABLE lists;
CREATE TABLE lists(id integer primary key, user_id integer, name varchar(50), creation_date datetime, importance integer, completed blob);

DROP TABLE list_item;
CREATE TABLE list_item(id integer primary key, list_id integer, name varchar(50), creation_date datetime, completed blob);

database.php代码:

<?php
class Database {

        private $database;

        function __construct() {
                $this->database = $this->getConnection();
        }

        function __destruct() {
                $this->database->close();
        }

        function exec($query) {
                $this->database->exec($query);
        }

        function query($query) {
                $result = $this->database->query($query);
                return $result;
        }

        function querySingle($query) {
                $result = $this->database->querySingle($query,true);
                return $result;
        }

        function prepare($query) {
                return $this->database->prepare($query);
        }
        function escapeString($string) {
                return $this->database->escapeString($string);
        }

        private function getConnection() {
                $conn = new SQLite3('todo.db');
                return $conn;
        }
}

2 个答案:

答案 0 :(得分:0)

正如@Darren建议的,它必须是action =&#34; target.php&#34; 这是一个错字。

答案 1 :(得分:0)

那么你尝试实现的目标至少是:

$created_date = date('Y-m-d H:i:s');
$db->exec("INSERT INTO lists 
VALUES(
   NULL,
   1,".
   SQLite3::escapeString ($listname).",
   $created_date ,
   $listimportance,".
   SQLite3::escapeString ('0')."
 );
");

您应该做的第一步,只需将此查询中的所有变量替换为任何值,并尝试获取结果