duagfgfn1981 2019-07-11 13:04
浏览 70
已采纳

从滚动条中选择如何检测选项或在表单提交的文本栏中输入值?

I am working to perform if else condition on form submission (POST Method) by detecting whether (the scroll option projectcode is selected AND the date is entered or not) OR (the value modifieddate is entered or not).

Based on the detection i am executing my if else conditions but things are not working.

I have a form inside in file dashboard.php

<form action='dashboardentry.php' method='post'>

    <label>Project Code: </label>
    <select name='projectcode'>
        <option value=''>Select...</option>
        <option value='COP-INT'>COP-INT</option>
    </select>

    <label>Date: </label>
    <input type='date' name='date'>

    <label>OR</label>

    <label>Modified Date: </label>

    <input type='text' name='modifieddate'>

    <button type='submit' name='delete'>Delete Entry</button>

</form>

I basically want to check whether to perform delete operation via project code and date variable value or via modified date in my database (has entries of hours spent) and for this i done below things.

In the file dashboardentry.php

<?php

if($_SERVER['REQUEST_METHOD'] === 'POST'){

    if(isset($_POST['projectcode']) AND isset($_POST['date'])){

    }elseif(isset($_POST['modifieddate'])){

    }else{

        echo "Please Enter either Project Code or Modified Date to delete Entry";

    }
?>

But my problem is that this if else is not working properly as per my expectation. plz help.

  • 写回答

1条回答 默认 最新

  • duananyantan04633 2019-07-11 13:14
    关注

    maybe check if values aren't not empty like this :

    <?php
    
    if($_SERVER['REQUEST_METHOD'] === 'POST'){
    
        if( isset($_POST['projectcode']) &&
            !empty($_POST['projectcode']) &&
            isset($_POST['date']) &&
            !empty($_POST['date'])){
    
        } else if(isset($_POST['modifieddate']) && !empty($_POST['modifieddate'])){
    
        } else{
    
        echo "Please Enter either Project Code or Modified Date to delete Entry";
    
    }
    
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.