php – 按钮停止发出POST请求

前端之家收集整理的这篇文章主要介绍了php – 按钮停止发出POST请求前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在这里遇到一个奇怪的问题,我有一段代码,直到昨天工作正常.我的按钮已停止发出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);但我没有收到任何错误或警告.

会话在两个页面中都启用.

任何帮助,将不胜感激.
提前致谢.

完整代码

ViewTeacherUpdatePage:

<?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相关文章