duanjue7508 2012-10-13 17:14
浏览 30
已采纳

从包含的文件中提交PHP表单运行功能

Sorry for the basic question. I have looked at other answers here on Stackoverflow but here goes:

I have a simple form which should post the data to my mysql DB:

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

and in the addTheatre.php file i have:

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

Which i should run the following function:

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 . "')");
    }

As far as i can tell, nothing is being submitted. As you can probably tell, i'm new to this, so apologies for the incompetence!

Thanks in advance for any help.

  • 写回答

3条回答 默认 最新

  • duanpoqiu0919 2012-10-13 17:32
    关注

    As you said, nothing being submitted, then probably your button doesn't have value and you trying to do

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

    it's ultimately false.

    So try to change your button

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

    To

    <input type="submit" class="submit" name="submit" value="Submit"/>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程