接收未定义的索引:FinalReviewDate错误

时间:2015-11-28 13:05:03

标签: php mysqli

我在代码的一行收到一个未定义的索引错误。我已经仔细检查了拼写并验证了它在我的数据库中的正确识别。我甚至换掉了另一段没有生成错误的代码,并将变量更改为无效。有问题的变量是FinalReviewDate。

    <h2>Project Updates</h2>
    <p class="first"></p>
    <form action="http://www.oldgamer60.com/Project/Update.php" method="post">

<div class="fieldset">
        <fieldset>

        Project: <input type="text" name="Project" value="<?php if(isset($Project)){ echo $Project; } ?>">
        <br><br>
        Client: <input type="text" name="Client" value="<?php if(isset($Client)){ echo $Client; } ?>">
        <br><br>
        Date Received: <input type="text" name="DateReceived" value="<?php if(isset($DateReceived)){ echo $DateReceived; } ?>">
        <br><br>
        Last Name: <input type="text" name="LastName" value="<?php if(isset($LastName)){ echo $LastName; } ?>">
        <br><br>
        Final Review Date: <input type="text" name="FinalReviewDate value="<?php if(isset($FinalReviewDate)){ echo $FinalReviewDate; } ?>">
        <br><br>
        Date Delivered: <input type="text" name="DateDelivered" value="<?php if(isset($DateDelivered)){ echo $DateDelivered; } ?>">
        <br><br>
        Date Accepted: <input type="text" name="DateAccepted" value="<?php if(isset($DateAccepted)){ echo $DateAccepted; } ?>">
        <br><br>
        <input type="submit" name="submit" value="Submit"> 
     </fieldset>
    </div>
    </form>
<br>

<?php
function test_input($data){
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
}

$servername = "localhost";
$username = "xxx";
$password = "xxx";
$dbname = "oldga740_SeniorProject";

// create connection
$connection = new mysqli($servername, $username, $password, $dbname);

if(isset($_POST['submit']) && !$connection->connect_error){
    // to track errors
    $error = false;

    // now validate input fields
      if(!preg_match("/^[a-zA-Z\s]{1,}$/",$_POST['Project'])){
        // check if project only contains letters and whitespace
        $ProjectErr = "Only letters and white space allowed";
        $error = true;
    }else{
        $Project = test_input($_POST['Project']);
    }

    if(!preg_match("/^[a-zA-Z\s]{1,}$/",$_POST['Client'])){
        // check if client only contains letters and whitespace
        $ClientErr = "Only letters, numbers and white space allowed";
        $error = true;
    }else{
        $Client = test_input($_POST['Client']);
    }

    if(!preg_match("/^[a-zA-Z\s]{1,}$/",$_POST['DateReceived'])){
        // check if last name only contains letters and whitespace
        $DateReceivedErr = "Only letters and white space allowed";
        $error = true;
    }else{
        $DateReceived = test_input($_POST['DateReceived']);
    }

   if(!preg_match("/^[a-zA-Z\s]{1,}$/",$_POST['LastName'])){
        // check if data received only contains letters and whitespace
        $LastNameErr = "Only letters and white space allowed";
        $error = true;
    }else{
        $LastName = test_input($_POST['LastName']);
    }

    if(!preg_match("/^[0-9]{1}-[0-9]{3}-[0-9]{3}-[0-9]{4}$/",$_POST['FinalReviewDate'])){
        // check if data received only contains letters and whitespace
        $FinalReviewDateErr = "Only letters and white space allowed";
        $error = true;
    }else{
        $FinalReviewDate = test_input($_POST['FinalReviewDate']);
    }


    if(!preg_match("/^[0-9]{1}-[0-9]{3}-[0-9]{3}-[0-9]{4}$/",$_POST['DateDelivered'])){
        // check if data received only contains letters and whitespace
        $DateDeliveredErr = "Only letters and white space allowed";
        $error = true;
    }else{
        $DateDelivered = test_input($_POST['DateDelivered']);
    }

    if(!preg_match("/^[0-9]{1}-[0-9]{3}-[0-9]{3}-[0-9]{4}$/",$_POST['DateAccepted'])){
        // check if data received only contains letters and whitespace
        $DateAcceptedErr = "Only letters and white space allowed";
        $error = true;
    }else{
        $DateAccepted = test_input($_POST['DateAccepted']);
    }

//set var field to update


    if(!$error){
        $query = "UPDATE `Projects` SET `Project`=[value-1],`Client`=[value-2],`DateReceived`=[value-3],`LastName`=[value-4],`FinalReviewDate`=[value-5],`DateDelivered`=[value-6],`DateAccepted`=[value-7] WHERE Project = '$Project'";

        if($connection->query($query)){
            echo "record is successfully updated!";
        }else{
            echo "error: record could not be updated";
        }
    }
}

?>



<?php
    $connection->close();
?>

1 个答案:

答案 0 :(得分:1)

忘记关闭名称属性

<input type="text" name="FinalReviewDate" value="<?php if(isset($FinalReviewDate)){ echo $FinalReviewDate; } ?>">
                                        ^