php - 按钮停止发出 POST 请求

标签 php http

我在这里遇到一个奇怪的问题,我有一段代码直到昨天都运行良好。突然我的按钮停止发出 POST 请求。 下面是示例代码。当我点击按钮 btnsubmit 时,页面被重定向到 view_teacherupdate.php 但它不打印“按钮已提交”;

<form  method="post" action="view_teacherUpdate.php">
  <input type="submit" name="btnsubmit" value="submit"/>
</form>

view_teacherUpdate.php

if(isset($_POST["btnsubmit"]))
{
  echo "button submitted";
}

我已启用 error_reporting(E_ALL); 但我没有收到任何错误或警告。

session 在两个页面中都已启用。

如有任何帮助,我们将不胜感激。 提前致谢。

完整代码:

查看教师更新页面:

<?php
session_start();
require_once 'includewisdom/class.user.php';
//require_once 'includewisdom/class.user.php';
error_reporting(E_ALL);
$user_home = new USER();

if(!$user_home->is_logged_in())
{
    $user_home->redirect('includewisdom/login.php');
}
function file_upload_error_message($error_code) {
    switch ($error_code) {
        case UPLOAD_ERR_INI_SIZE:
            return 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
        case UPLOAD_ERR_FORM_SIZE:
            return 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
        case UPLOAD_ERR_PARTIAL:
            return 'The uploaded file was only partially uploaded';
        case UPLOAD_ERR_NO_FILE:
            return 'No file was uploaded';
        case UPLOAD_ERR_NO_TMP_DIR:
            return 'Missing a temporary folder';
        case UPLOAD_ERR_CANT_WRITE:
            return 'Failed to write file to disk';
        case UPLOAD_ERR_EXTENSION:
            return 'File upload stopped by extension';
        default:
            return 'Unknown upload error';
    }
}

if(isset($_POST["btnUpdateNew"]))
{
    echo "hfvghfhgfhgf enter";
    $TeacherID=5;
    $teachername=trim($_POST["teachername"]);
    $current_address=trim($_POST["current_address"]);
    $teaching_locationsarray=$_POST["teaching_locations"];
    $teaching_locationsarray=array_unique($teaching_locationsarray);
    $teaching_location="";
        foreach($teaching_locationsarray as $temp)
        {
        $teaching_location=$temp.",".$teaching_location;
        }
    $teaching_location=rtrim($teaching_location,",");
        //echo $teaching_location;
    $teachingzone=trim($_POST["teachingzone"]);
    //$TeacherLocation[]
    $TeacherLocationarray=$_POST["TeacherLocation"];
    $TeacherLocationarray=array_unique($TeacherLocationarray);
    $TeacherLocation="";
        foreach($TeacherLocationarray as $temp)
        {
        $TeacherLocation=$temp.",".$TeacherLocation;
        }
    $TeacherLocation=rtrim($TeacherLocation,",");
    //$residenceZone=trim($_POST["residenceZone"]);
    //$Teaching_subject[]
    $Teaching_subjectarray=$_POST["Teaching_subject"];
    $Teaching_subjectarray=array_unique($Teaching_subjectarray);
    $Teaching_subject="";
        foreach($Teaching_subjectarray as $temp)
        {
        $Teaching_subject=$temp.",".$Teaching_subject;
        }
    $Teaching_subject=rtrim($Teaching_subject,",");
    //$residenceZone=trim($_POST["residenceZone"]);
    //$TeachingGroup[]
    $TeachingGrouparray=$_POST["TeachingGroup"];
    $TeachingGrouparray=array_unique($TeachingGrouparray);
    $TeachingGroup="";
        foreach($TeachingGrouparray as $temp)
        {
        $TeachingGroup=$temp.",".$TeachingGroup;
        }
    $TeachingGroup=rtrim($TeachingGroup,",");
    //$residenceZone=trim($_POST["residenceZone"]);
    //$edu_subject[]
    $edu_subjectarray=$_POST["edu_subject"];
    $edu_subjectarray=array_unique($edu_subjectarray);
    $edu_subject="";
        foreach($edu_subjectarray as $temp)
        {
        $edu_subject=$temp.",".$edu_subject;
        }
    $edu_subject=rtrim($edu_subject,",");
    //$residenceZone=trim($_POST["residenceZone"]);
    //$EducationGroup[]
    $EducationGrouparray=$_POST["EducationGroup"];
    $EducationGrouparray=array_unique($EducationGrouparray);
    $EducationGroup="";
        foreach($EducationGrouparray as $temp)
        {
        $EducationGroup=$temp.",".$EducationGroup;
        }
    $EducationGroup=rtrim($EducationGroup,",");
    $residenceZone=trim($_POST["residenceZone"]);
    $gender=trim($_POST["gender"]);
    $board=trim($_POST["board"]);
    $Qualification=trim($_POST["Qualification"]);
    $enrollmentdate=trim($_POST["enrollmentdate"]);
    $dob=trim($_POST["dob"]);
}

ViewTeacherPage(点击按钮的地方)

<?php
session_start();
require_once 'includewisdom/class.user.php';
//require_once 'includewisdom/class.user.php';
error_reporting(E_ALL);
define('PAC_PATH','phpAutocomplete');
require_once("phpAutocomplete/conf.php");
$user_home = new USER();

if(!$user_home->is_logged_in())
{
    $user_home->redirect('includewisdom/login.php');
}
$tutorRequirement=[];

if(isset($_POST["deleteDocs"]))
{
    $TeacherID=trim($_GET["id"]);
    //echo $TeacherID;
    $stmt1 = $user_home->runQuery("UPDATE `teacher_info` SET `idproof`='',`degree`='',`marksheet`='',`tenmarksheet`='',`degreemarksheet`='',
    `additionalDocuments`='',
`addressproof`='' WHERE userid=:uid");
            $stmt1->bindparam(":uid",$TeacherID);
            $stmt1->execute();  
    //echo "sgadjfdgs";
}



if(isset($_POST["submitRequestRequirement"]))
{
    $noteid=trim($_GET["noteid"]);
    $tutorid=trim($_GET["id"]);
    $stmtInsert="";
    $stmtRequest = $user_home->runQuery("SELECT * FROM `TutorRequestRequirement` WHERE TutorID='$tutorid' and RequestID='$noteid'");
    $stmtRequest->execute();
    //fetch(PDO::FETCH_ASSOC)
    $tutorRequirement = $stmtRequest->fetchAll(PDO::FETCH_ASSOC);

    $requestRequirement=trim($_POST["requestRequirement"]);
    if(count($tutorRequirement)>0)
    {
        $stmtInsert = $user_home->runQuery("Update TutorRequestRequirement set Requirement=:Requirement where TutorID=:TutorID and RequestID=:RequestID");
    }
    else
    {
    $stmtInsert = $user_home->runQuery("INSERT INTO `TutorRequestRequirement`(`TutorID`, `Requirement`, `RequestID`) Values
            (:TutorID,:Requirement,:RequestID)");   
    }

            $stmtInsert->bindparam(":TutorID",$tutorid);
            $stmtInsert->bindparam(":Requirement",$requestRequirement);
            $stmtInsert->bindparam(":RequestID",$noteid);
            $result=$stmtInsert->execute();

}
if(isset($_GET["noteid"]))
{
    $noteid=trim($_GET["noteid"]);
    $tutorid=trim($_GET["id"]);
    $stmtRequest = $user_home->runQuery("SELECT * FROM `TutorRequestRequirement` WHERE TutorID='$tutorid' and RequestID='$noteid'");
    $stmtRequest->execute();
    //fetch(PDO::FETCH_ASSOC)
    $tutorRequirement = $stmtRequest->fetchAll(PDO::FETCH_ASSOC);
    //echo count($tutorRequirement);
    //var_dump($tutorRequirement);
}

function file_upload_error_message($error_code) {
    switch ($error_code) {
        case UPLOAD_ERR_INI_SIZE:
            return 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
        case UPLOAD_ERR_FORM_SIZE:
            return 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
        case UPLOAD_ERR_PARTIAL:
            return 'The uploaded file was only partially uploaded';
        case UPLOAD_ERR_NO_FILE:
            return 'No file was uploaded';
        case UPLOAD_ERR_NO_TMP_DIR:
            return 'Missing a temporary folder';
        case UPLOAD_ERR_CANT_WRITE:
            return 'Failed to write file to disk';
        case UPLOAD_ERR_EXTENSION:
            return 'File upload stopped by extension';
        default:
            return 'Unknown upload error';
    }
}


$stmt = $user_home->runQuery("SELECT * FROM RoleInfoWisdomManagementSystem WHERE id=:uid");
$stmt->execute(array(":uid"=>$_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$msg = "<div class='alert alert-block' style='background:#48cfad;margin-top:10px'>
                        <button class='close' data-dismiss='alert'>&times;</button>
                        <strong>  Your Profile Updated Successfully. </strong>
                        </div>";
$role=$row['role'];
$name=$row['Name'];

$TeacherID=trim($_GET["id"]);
$stmt = $user_home->runQuery("SELECT * FROM teacher_info WHERE userid=:uid");
$stmt->execute(array(":uid"=>$TeacherID));
$row = $stmt->fetch(PDO::FETCH_ASSOC);

$teachingPreferencearray=explode(",",$row["tution_type"]);

$stmtArea = $user_home->runQuery("SELECT * FROM kolkata_locations");
$stmtArea->execute();
$rowarea = $stmtArea->fetchAll();

$stmt112 = $user_home->runQuery("SELECT distinct `subject_name` FROM `subjects`");
$stmt112->execute();
$rowsubjects = $stmt112->fetchAll();

$stmt1123 = $user_home->runQuery("SELECT * FROM `subjects`");
$stmt1123->execute();
$rowTeachingsubjects = $stmt1123->fetchAll();
//$arrinbox=explode("#",$inbox);

<form  method="post" action="view_teacherUpdate.php">
<button id="btnUpdate" name="btnUpdateNew" value="btnUpdateNew"  type="submit" class="btn btn-success">Save</button>

      </form>

最佳答案

您提交的代码包含2个提交按钮(1 < button >, 1 < input type="submit">。根据按下的按钮,实际提交了不同的值。我猜表单只添加了按钮(或元素类型=提交)实际被点击到 POST 数据(从 UI 的角度来看这是有意义的)

根据按下的按钮,我得到了

Array ( [btnsubmit] => Verzenden )

Array ( [btnUpdateNew] => btnUpdateNew )

(“Verzenden”是 Send 的荷兰语翻译,浏览器对此进行了翻译)

那么,有没有可能是你按错了按钮?

<form  method="post" action="view_teacherUpdate.php">
  <input type="submit" name="btnsubmit"/>
  <button id="btnUpdate" name="btnUpdateNew" value="btnUpdateNew" type="submit" class="btn btn-success">Save</button>
</form>

关于php - 按钮停止发出 POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40806963/

相关文章:

PHP Pascal 三 Angular 形在表格中显示不正确

php - 使用 Zend_Mail 添加多个收件人

c# - 如何模拟一次请求时的主机文件

php - 如何检查客户端是否接受特定的返回类型?

linux - 如何将 tail -f 输出重定向到 curl(HTTP 流)

php - 我的 WordPress 网站打开速度太慢

php - 使用 Zend_Form 生成动态输入

php - mysqli_connect() 不适用于 PHP 和 Tomcat

javascript - 当响应头 'Content-Type' 设置为 'application/json' 时,HTTP 响应正文可以为空吗?

javascript - Node.js 未对 HTTP 响应 header 使用 ISO-8859-1 编码