提交始终重定向到同一页面操作不起作用

时间:2016-08-08 10:03:33

标签: javascript php jquery html forms

即时创建一个表单,使用select选项更改/更新我的票证状态,但每当我提交时。它只是进入自我页面。这是地址" http://localhost/support/admin-post.php?td=10&id=1"当我点击提交时,会发生这种情况" http://localhost/support/admin-post.php?ticketstats%5B%5D=Pending#"。它应该转到" status-update.php"。我试过把它放在仍然不工作,我尝试使用,但不能得到选择值,这就是为什么我选择PHP方法,而这里是我的代码

<div class="hide" id="status">
            <form id="myform" role="form" action="ticket.php" method="POST">
        <select class="form-control" type="text" name="ticketstats[]">
            <option><?php echo $status ?></option>
            <option class="disabled">--------------</option>
            <option value="Pending">Pending</option>
            <option value="Open">Open</option>
            <option value="Closed">Closed</option>
        </select> 
            <input class="btn pull-right" type="submit"> 
            <a class="btn pull-left" id="cancelstatus" href="#">Cancel</a>
            </form>
    </div>

<?php
if(isset($_POST['submit'])){

    foreach ($_POST['ticketstats'] as $select)
    {

        echo "<script>window.open('status-update.php?    td=$ticketid&id=$empinfoid&stats=$select','_self')</script>";
    }
}
?>


    <a class="pull-right" id="editstatus" href="#">Change</a>
    <div id="status-duetime" class="post-footer"><?php echo time_elapsed_ago($date) ?> </div>
</div>
</div>

这是我的main.js

var change = document.querySelector("#editstatus");
var cancel = document.querySelector("#cancelstatus");
var statuss = document.querySelector("#status");
var nowstatus = document.querySelector("#nowstatus");
var statusduetime = document.querySelector("#status-duetime");


change.addEventListener("click",edits)
cancel.addEventListener("click",edits)

function edits() {
if (statuss.className === "hide") {
    statuss.className = "";
    statusduetime.className = "hide";
    nowstatus.className = "hide";
    change.className = "hide";
} else {
    statuss.className = "hide";
    statusduetime.className = "post-footer";
    nowstatus.className = "pending";
    change.className = "pull-right";
}

}

这是我的行动状态-update.php

<?php
include("database/db_conection.php");   

$ticketid = $_GET['td'];
$empinfoid = $_GET['id'];

if($_POST) {
$sql = "UPDATE employee_tickets SET TicketStatus='".$_GET['stats']."'         WHERE Id='".$_GET['td']."'";


if (!mysqli_query($conn,$sql)) {
die('Error: ' . mysqli_error($conn));
}

echo "<script>window.open('admin-post.php?td=$ticketid&id=$empinfoid','_self')</script>";
$conn->close();

}
?>

1 个答案:

答案 0 :(得分:2)

如果您没有给提交按钮name="???"属性,则无法在PHP中对其进行测试

所以将此行更改为

<input name="submit" class="btn pull-right" type="submit"> 
       ^^^^^^^^^^^^^

PHP中的这一行

if(isset($_POST['submit'])){

将有一些东西要测试。

摆脱这一行的空间也是一个好主意

echo "<script>window.open('status-update.php?    td=$ticketid&id=$empinfoid&stats=$select','_self')</script>";
                                             ^^^^

您的表单action="ticket.php"也不会运行脚本status-update.php它将运行ticket.php