doujiao1948 2015-06-17 08:49
浏览 19
已采纳

如何将表单发布到相同的php页面并拦截它?

I'm trying to submit a form to same page, so I want submit data, and then save into DB... And then update my page with new data...

I do it in this way:

 <?php
                     if (isset($_POST["matricola"]) && isset($_POST["pc"])){
                         echo "QUI";
                        $conn = dbConnect($USERDB, $PASSWORDDB, $NAMEDB); //seleziono il database e mi connetto

                        $matricola = $_POST['matricola'];
                        $pc = $_POST['pc'];

                        $queryGetUser = "select id from user where matricola = ".$matricola;
                        $user = dbQueryGetResult($queryGetUser);

                        $today = getdate();
                        $data = $today['mday']."/".$today['month']."/".$today['year']; 
                        $ora = $today['hours'].":".$today['minutes'].":".$today['seconds'];

                        $sql = "insert into utelenza (id_user, id_pc, dataEntrata, oraEntrata) values (".$user[0].", ".$pc.", ".$data.", ".$ora.")";
                        dbQueryInsert($sql);
                     }                    
                    //Prendo dal DB le note del laboratorio visualizzabili da tutti
                    $conn = dbConnect($USERDB, $PASSWORDDB, $NAMEDB);
                    $queryGetNoteLab = "select noteLaboratorio from laboratorio where id_laboratorio = " . $IDLAB;
                    $notaLab = dbQueryGetResult($queryGetNoteLab);

                    $queryGetInfoLab = "select info150ore from laboratorio where id_laboratorio = " . $IDLAB;
                    $infoLab = dbQueryGetResult($queryGetInfoLab);

                    $queryGetPcs = "select * from pc where id_laboratorio = " . $IDLAB;
                    $pcs = dbQueryReturnMatrix($queryGetPcs);

                    dbDisconnect($conn);

                    echo "<form action='home150.php' method='post'>"
                    . "<table><tr><td>Matricola</td><td><input id='matricola' type='text' ></td></tr>"
                    . "<tr><td>PC</td><td><select id='pc'><option value=''></option>";

                    for ($i = 0; $i < count($pcs); $i++) {
                        echo "<option value=" . $pcs[$i][0] . ">" . $pcs[$i][2] . "</option>";
                    }
                    echo "</select></td></tr></table>"
                    . "<input id='submitButton' type='submit' value='Inserisci'></form>";
                    ?>

The form submitted, but after submit I can't intercept the data post..

Why?? How can I fix it??

Thank you!

  • 写回答

2条回答 默认 最新

  • dtkl55257 2015-06-17 08:56
    关注

    change your form like this if you want to submit form in same page then no need to give form action give submit button a name and use isset in php code for button's submit

    <form action='' method='post'>"
        <table>
            <tr>
                <td>Matricola</td>
                <td>
                    <input id='matricola' type='text'>
                </td>
            </tr>
            <tr>
                <td>PC</td>
                <td>
                    <select id='pc'>
                        <option value=''></option>
    
                        <?php for ($i=0 ; $i < count($pcs); $i++) {?>
                        <option value="<?php echo $pcs[$i][0]?>">
                            <?php echo $pcs[$i][2]?>
                        </option>
                        <?php }?>
                    </select>
                </td>
            </tr>
        </table>
        <input id='submitButton' type='submit' value='Inserisci' name="submit">
    </form>
    
    <?php if(isset($_POST['submit']))
    {
    //your query for insert or whatever
    }?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了