从echo输入字段获取值

时间:2017-01-02 23:36:59

标签: php

如果数据库中有记录,我有一个用php检查的表单。 如果数据库中存在记录,则输入框将自动填充。 我已经这样做了,不用担心。 问题是如果我想修改输入框中的文本,那么我无法获得输入框的新值。我怎么能这样做?

<?php
$title="Welcome";

require("connect.php");


session_start();

if(isset($_SESSION['CurrentUser'])) {
    $AppID=$_SESSION['CurrentUser'];
}
else{
    header("Location: ApplicantLogin.php");
}

$Flag = mysql_query("SELECT EXISTS(SELECT 1 FROM Submission WHERE AppID='$AppID') AS FLAG");
$SubmissionDetailSQL=mysql_query("SELECT * FROM Submission WHERE AppID = '$AppID'");

function saveData() {
    if (isset($_POST['QualificationPlace']) && isset($_POST['QualificationType']) && isset($_POST['QualificationInstitution']) && isset($_POST['QualificationMonth']) 
        && isset($_POST['QualificationYear']) && isset($_POST['QualificationSubject']) && isset($_POST['QualificationGrade'])){

        $QualificationPlace = $_POST['QualificationPlace'];
        $QualificationType = $_POST['QualificationType'];
        $QualificationInstitution = $_POST['QualificationInstitution'];
        $QualificationMonth = $_POST['QualificationMonth'];
        $QualificationYear = $_POST['QualificationYear'];
        $QualificationSubject = $_POST['QualificationSubject'];
        $QualificationGrade = $_POST['QualificationGrade'];

        mysql_query("UPDATE Submission SET QualificationPlace='$QualificationPlace', QualificationType='$QualificationType',
            QualificationInstitution='$QualificationInstitution', QualificationMonth='$QualificationMonth', QualificationYear='$QualificationYear',
            QualificationSubject='$QualificationSubject', QualificationGrade='$QualificationGrade' WHERE AppID=$AppID");
    }
}

if (isset($_POST['savebtn'])) {
    saveData();
    header("Location: applicantCase.php");
}
if (isset($_POST['nextbtn'])) {
    saveData();
    header("Location: ApplicantApplyEmployment.php");
}

if (mysql_fetch_array($Flag) == True) {
    while ($SubmissionDetails=mysql_fetch_array($SubmissionDetailSQL)){
        $_SESSION['QualificationPlace']=$SubmissionDetails['QualificationPlace'];
        $_SESSION['QualificationType']=$SubmissionDetails['QualificationType'];
        $_SESSION['QualificationInstitution']=$SubmissionDetails['QualificationInstitution'];
        $_SESSION['QualificationMonth']=$SubmissionDetails['QualificationMonth'];
        $_SESSION['QualificationYear']=$SubmissionDetails['QualificationYear'];
        $_SESSION['QualificationSubject']=$SubmissionDetails['QualificationSubject'];
        $_SESSION['QualificationGrade']=$SubmissionDetails['QualificationGrade'];
    }
}


include( "html/applicantsheader.html" );
include( "html/ApplicantApplyQualifications.html" );
include( "html/footer.html" );
?>

HTML代码:

<div class="col-sm-4 col-sm-offset-5 col-md-4 col-md-offset-5 main">
<h1 class="page-header">Qualifications</h1>
<form action="ApplicantApplyQualifications.php" method="POST">
    <!-- Select Basic -->
        <fieldset class="form-group">
            <label for="Name">Where was the qualification taken?</label>
            <?php echo "<input type='text' name='QualificationPlace' class='form-control' placeholder=''value=".$_SESSION['QualificationPlace'].">" ;?>
        </fieldset>
        <fieldset class="form-group">
            <label for="Name">Qualification Type</label>
            <?php echo "<input type='text' name='QualificationType' class='form-control' placeholder=''value=".$_SESSION['QualificationType'].">" ;?>
        </fieldset>
        <fieldset class="form-group">
            <label for="Name">Awarding Institution</label>
            <?php echo "<input type='text' name='QualificationInstitution' class='form-control' placeholder=''value=".$_SESSION['QualificationInstitution'].">" ;?>
        </fieldset>
        <fieldset class="form-group">
            <label for="Surname">Month / Year</label>
            <div class="input-group">
                <?php echo "<input type='text' name='QualificationMonth' class='form-control' placeholder=''value=".$_SESSION['QualificationMonth'].">" ;?>
                <span class="input-group-addon">-</span>
                <?php echo "<input type='text' name='QualificationYear' class='form-control' placeholder=''value=".$_SESSION['QualificationYear'].">" ;?>
            </div>
        </fieldset>
        <fieldset class="form-group">
            <label for="Surname">Subject</label>
            <?php echo "<input type='text' name='QualificationSubject' class='form-control' placeholder=''value=".$_SESSION['QualificationSubject'].">" ;?>
        </fieldset>
        <fieldset class="form-group">
            <label for="Surname">Grade</label>
            <?php echo "<input type='text' name='QualificationGrade' class='form-control' placeholder=''value=".$_SESSION['QualificationGrade'].">" ;?>
        </fieldset>

     <br>
      <button type="submit" value="signup" name="savebtn" class="btn btn-primary">Save & Exit</button>
      <button type="submit" value="signup" name="nextbtn" class="btn btn-primary">Next</button>
    </form>
        </div> <!-- /container -->

问题必须是值=&#34;。$ _ SESSION [&#39; QualificationPlace&#39;]。&#34;。但我怎么能以不同的方式做到这一点?

2 个答案:

答案 0 :(得分:0)

我认为问题可能出在你设置会话的地方。

创建另一个设置会话的功能,以便每次更新数据时都可以这样做。

<?php
$title="Welcome";

require("connect.php");


session_start();

if(isset($_SESSION['CurrentUser'])) {
    $AppID=$_SESSION['CurrentUser'];
}
else{
    header("Location: ApplicantLogin.php");
}

$Flag = mysql_query("SELECT EXISTS(SELECT 1 FROM Submission WHERE AppID='$AppID') AS FLAG");
$SubmissionDetailSQL=mysql_query("SELECT * FROM Submission WHERE AppID = '$AppID'");

function saveData() {
    if (isset($_POST['QualificationPlace']) && isset($_POST['QualificationType']) && isset($_POST['QualificationInstitution']) && isset($_POST['QualificationMonth']) 
        && isset($_POST['QualificationYear']) && isset($_POST['QualificationSubject']) && isset($_POST['QualificationGrade'])){

        $QualificationPlace = $_POST['QualificationPlace'];
        $QualificationType = $_POST['QualificationType'];
        $QualificationInstitution = $_POST['QualificationInstitution'];
        $QualificationMonth = $_POST['QualificationMonth'];
        $QualificationYear = $_POST['QualificationYear'];
        $QualificationSubject = $_POST['QualificationSubject'];
        $QualificationGrade = $_POST['QualificationGrade'];

        mysql_query("UPDATE Submission SET QualificationPlace='$QualificationPlace', QualificationType='$QualificationType',
            QualificationInstitution='$QualificationInstitution', QualificationMonth='$QualificationMonth', QualificationYear='$QualificationYear',
            QualificationSubject='$QualificationSubject', QualificationGrade='$QualificationGrade' WHERE AppID=$AppID");

        // use new values to set the session details
        setSessionDetails($_POST);

    }
}
// new function to set the session
function setSessionDetails($SubmissionDetails) {
    $_SESSION['QualificationPlace']=$SubmissionDetails['QualificationPlace'];
    $_SESSION['QualificationType']=$SubmissionDetails['QualificationType'];
    $_SESSION['QualificationInstitution']=$SubmissionDetails['QualificationInstitution'];
    $_SESSION['QualificationMonth']=$SubmissionDetails['QualificationMonth'];
    $_SESSION['QualificationYear']=$SubmissionDetails['QualificationYear'];
    $_SESSION['QualificationSubject']=$SubmissionDetails['QualificationSubject'];
    $_SESSION['QualificationGrade']=$SubmissionDetails['QualificationGrade'];
}

if (isset($_POST['savebtn'])) {
    saveData();
    header("Location: applicantCase.php");
}
if (isset($_POST['nextbtn'])) {
    saveData();
    header("Location: ApplicantApplyEmployment.php");
}

if (mysql_fetch_array($Flag) == True) {
    while ($SubmissionDetails=mysql_fetch_array($SubmissionDetailSQL)){
        // set the session from db
        setSessionDetails($SubmissionDetails);
    }
}


include( "html/applicantsheader.html" );
include( "html/ApplicantApplyQualifications.html" );
include( "html/footer.html" );
?>

答案 1 :(得分:0)

问题是我必须使用$ AppID参数调用函数saveData()。我很抱歉这一切混乱。我正在努力工作11个小时,我想我的大脑关闭了。 谢谢大家的帮助。我试图解决这个问题好几个小时,但是在发布之后我就看到了这个错误,所以我很抱歉。