字段为空时,PHP代码不会回显错误消息

时间:2019-05-07 13:31:38

标签: php echo

变更请求表单成功显示一条确认消息,表明已提交请求,但是,当描述字段留为空白时,我要显示一条错误消息,指出“请在提交之前输入变更请求描述”。代码没有这样做。

$con = mysqli_connect('localhost', 'dm459', 'dm459');
if (!$con) {
    echo '<p class="error">Not connected To Server</p>';
}
if (!mysqli_select_db($con,'dm459_kiamycontacts')) {
    echo '<p class="error">Database Not Selected</p>';
}
if (isset($_POST['typename'])) {
    $requesttype = $_POST['typename'];
}
if (isset($_POST['date'])) {
    $date = $_POST['date'];
}
if (isset($_POST['comment'])) {
    $comment = $_POST['comment'];
}
if (isset($_SESSION['UserId'])) {
    $logUserId = $_SESSION['UserId'];
}
if (isset($_POST['submit'])) {
    $sql = "INSERT INTO
    `changerequest` (requestDate,requestDescription,personnelID,requestTypeID)
    VALUES ('$date','$comment',$logUserId, $requesttype)";

    if (mysqli_query($con, $sql)) {
        echo '<p class="error">Change Request Successfully Submitted</p>';
    } elseif (empty($_POST['comment'])) {
        echo '<p class="error">Please Enter the Change Request Description Before Submitting</p>';
    } else {
        echo '<p class="error">Change Request Error</p>';
    }
}

0 个答案:

没有答案