0

对不起,基本问题。我在 Stackoverflow 上查看了其他答案,但这里是:

我有一个简单的表格,应该将数据发布到我的 mysql 数据库中:

<form id="theatre" method="post" action="{$HTTP_HOST}admin/addTheatre.php"     autocomplete="on">
    <input type="hidden" name="id">
    <fieldset>
        <label>Please fill in the relevent fields.</label>
        <section>
            <label for="year">Year</label>
            <div>                   
                <select name="year" id="year">
                    <optgroup label="Year">
                            <option>2013</option>
                            <option>2012</option>
                            <option>2011</option>
                            <option>2010</option>
                            <option>2009</option>
                            <option>2008</option>
                            <option>2007</option>
                            <option>2006</option>
                    </optgroup>
                </select>
            </div>
        </section>
        <section><label for="part">Part</label>
            <div>
                <input type="text" id="part" name="part" title="A Tooltip">
            </div>
        </section>
        <section><label for="name">Name</label>
            <div>
                <input type="text" id="name" name="name" title="A Tooltip">
            </div>
        </section>
        <section><label for="theatre">Theatre</label>
            <div>
                <input type="text" id="theatre" name="theatre" title="A Tooltip">
            </div>
        </section>
        <section><label for="director">Director</label>
            <div>
                <input type="text" id="director" name="director" title="A Tooltip">
            </div>
        </section>
        <section>
            <div>
                <button name="submit" class="submit" type="submit">Submit</button>
            </div>
        </section>
    </fieldset>
</form>

在 addTheatre.php 文件中我有:

if(isset($_POST['submit'])){
    hcDB::getInstance()->insert_theatre($_POST['year'], $_POST['part'], $_POST['name'], $_POST['theatre'], $_POST['director']);
}

我应该运行以下功能:

function insert_theatre($year, $part, $name, $theatre, $director) {
    $year = $this->real_escape_string($year);
    $part = $this->real_escape_string($part);
    $name = $this->real_escape_string($name);
    $theatre = $this->real_escape_string($theatre);
    $director = $this->real_escape_string($director);
    $this->query("INSERT INTO theatre (`year`, `part`, `name`, `theatre`, `director`)" .
            " VALUES (" . $year . "' , '" . $part . "' , '" . $name . "' , '" . $theatre . "' , '" . $director . "')");
    }

据我所知,没有提交任何内容。你可能会说,我是新手,所以为无能道歉!

提前感谢您的帮助。

4

3 回答 3

0

检查返回值query并调用errorInfo以查看是否收到任何有意义的消息。

它可能应该告诉您 SQL 格式错误:

$this->query("INSERT INTO theatre (`year`, `part`, `name`, `theatre`, `director`)" .
        " VALUES (" . $year . "' , '" . $part . "' , '" . $name . "' , '" . $theatre . "' , '" . $director . "')");
}

AFAICTVALUES ("应更改为VALUES('"(额外的单引号)。

于 2012-10-13T17:18:47.113 回答
0

您的查询中有错字,并且没有错误处理,因此您永远不会看到 mysql 会提供的错误消息:

" VALUES ('" . $year . "' , '"
          ^--- missing quote
于 2012-10-13T17:19:00.297 回答
0

正如您所说,没有提交任何内容,那么您的按钮可能没有价值并且您正在尝试做

if(isset($_POST['submit'])){
//other stuff
}

它最终是错误的。

所以试着改变你的按钮

<button name="submit" class="submit" type="submit">Submit</button>

<input type="submit" class="submit" name="submit" value="Submit"/>
于 2012-10-13T17:32:11.883 回答