-1

一旦满足 if 条件,我想将日期时间戳插入变量中。但我收到以下错误:

注意:未定义索引:第 55 行 C:\wamp\www\business\edit_log_widget.php 中的状态

以下是php代码:

<?php
    include 'scripts/init.php';
    include 'html/header.php';
    $page = 'servers';

    $id =$_SESSION['logid'];
    $query = "SELECT *FROM log WHERE logid = $id";
    $query_submit = mysql_query($query) or die(mysql_error);
    $row = mysql_fetch_assoc($query_submit);
?>

<div class="article">
    <h2><span>Edit Logs</span></h2>
    <div class="clr"></div>
    <form action="" method="POST" >
    <p>
        <table border="0">
            <tr>
                <td><label for="Task Name">Task Name:*</label></td>
                <td><input type="text" name="task_name" size="45" value="<?php echo $row['task_name'] ?>"/></td>
            </tr>
            <tr>
                <td><label for="description">Problem Description:*</label></td>
                <td><textarea name="description" cols="33" rows="10" ><?php echo $row['description'] ?></textarea></td>
           </tr>
           <tr>
                <td><label for="solution">Solution Description:*</label></td>
                <td><textarea name="solution" cols="33" rows="10" ><?php echo $row['solution'] ?></textarea></td>
           </tr>
           <tr>
                <td><label for="status">Status:*</label></td>
                <td>
                    <select id="Select2" name="status">
                        <option>-Select-</option>
                        <option>Resolved</option>
                        <option>Un-resolved</option>
                        <option>In-Progress</option>
                    </select>
                </td>
           </tr>
        </table>
    </p>
    <p>
        <td><input id="Submit" type="submit" value="Submit" /></td>
        <td><input id ="Clear and Restart" type ="reset" value= "Clear and Restart" /></td>
    </p>
    <?php 
        if($_POST['status']== 'Resolved')
        {
            $today = DateTime::createFromFormat('!Y-m-d',date('Y-m-d')); // This is Line 55
        }

        if(isset($_GET['success']) && empty($_GET['sucess']))
        {
            echo 'the log has been captured';
        }
        else
        {
            if(empty($_POST) === false && empty($errors)=== true)
            {
                //Update Log details
                $update_log = array(
                                'task_name'=>$_POST['task_name'],
                                'description' => $_POST['description'],
                                'solution' =>$_POST['solution'],
                                'status'=>$_POST['status'],
                                'closed_date'=>$today,
                                'userid' =>$_SESSION['userid']);
                update_log($update_log);
                //redirect
                header('Location: edit_log_widget.php?success');
                exit();
            }
            else if(empty($errors) === false)
            {
                //output errors if the errors array is not empty
                echo output($errors);
            }
        }
    ?>
    </form>  
    <?php
        include 'html/side_menu.php';
        include 'html/footer.php';
    ?>

更新:edit_log.php。

<?php
    include 'scripts/init.php';
    include 'html/header.php';
    $page = 'servers';

    $id = $_GET['logid'];
    $_SESSION['logid'] = $id;
    $query = "SELECT *FROM log WHERE logid = $id";
    $query_submit = mysql_query($query) or die(mysql_error);
    $row = mysql_fetch_assoc($query_submit);
?>

<div class="article">
    <h2><span>Edit Logs</span></h2>
    <div class="clr"></div>
    <form action="edit_log_widget.php" method="POST" >
    <p>
        <table border="0">
            <tr>
                <td><label for="Task Name">Task Name:*</label></td>
                <td><input type="text" name="task_name" size="45" value="<?php echo $row['task_name'] ?>"/></td>
            </tr>
            <tr>
                <td><label for="description">Problem Description:*</label></td>
                <td><textarea name="description" cols="33" rows="10" ><?php echo $row['description'] ?></textarea></td>
            </tr>
            <tr>
                <td><label for="solution">Solution Description:*</label></td>
                <td><textarea name="solution" cols="33" rows="10" ><?php echo $row['solution'] ?></textarea></td>
            </tr>
            <tr>
                <td><label for="status">Status:*</label></td>
                <td>
                    <select id="Select2" name="status">
                        <option>-Select-</option>
                        <option value="Resolved">Resolved</option>
                        <option value="Un-resolved">Un-resolved</option>
                        <option value="In-Progress">In-Progress</option>
                    </select>
                </td>
            </tr>
        </table>
    </p>
    <p>
        <td><input id="Submit" type="submit" value="Submit" /></td>
        <td><input id ="Clear and Restart" type ="reset" value= "Clear and Restart" /></td>
    </p>
</form>  
<?php
    include 'html/side_menu.php';
    include 'html/footer.php';
?>
4

5 回答 5

0

您没有为您的选项指定任何价值;)

<option value="Resolved">Resolved</option>
于 2013-02-13T10:23:22.267 回答
0
$_POST['status']

数组 $_POST 的入口状态未定义

您正在尝试访问尚未设置的变量。

为避免这种情况,您可以先检查表单是否在之前提交,例如

<?php 
        if(!empty($_POST['Submit'])){

                    if($_POST['status']== 'Resolved')
                        {
                            $today = DateTime::createFromFormat('!Y-m-d',date('Y-m-d')); // This is Line 55

                        }


                    if(isset($_GET['success']) && empty($_GET['sucess']))
                        {
                            echo 'the log has been captured';
                        }
                    else
                        {
                            if(empty($_POST) === false && empty($errors)=== true)
                                {
                                                                            //Update Log details
                                    $update_log = array(
                                    'task_name'=>$_POST['task_name'],
                                    'description' => $_POST['description'],
                                    'solution' =>$_POST['solution'],
                                    'status'=>$_POST['status'],
                                    'closed_date'=>$today,
                                    'userid' =>$_SESSION['userid']);


                                    update_log($update_log);
                                    //redirect
                                    header('Location: edit_log_widget.php?success');
                                    exit();

                                }
                            else if(empty($errors) === false)
                                {
                                    //output errors if the errors array is not empty
                                    echo output($errors);
                                }
                        }
                    }
            ?>
于 2013-02-13T10:24:04.780 回答
0

PHP 代码在表单提交之前执行,因此 $_POST['status'] 尚未定义。

于 2013-02-13T10:24:55.960 回答
0

你缺少一些 html 道具,你<option>必须有这样的value道具:

<td>
   <select id="Select2" name="status">
      <option value="0">-Select-</option>
      <option value="1">Resolved</option>
      <option value="2">Un-resolved</option>
      <option value="3">In-Progress</option>
    </select>
</td>

你得到这个错误是因为你在你的第一个 html 片段中丢失了它,而你在第二个片段中有它,所以 PHP 没有什么可以得到的

于 2013-02-13T11:27:00.730 回答
0

我将所有的 php 移到了 html 表单的顶部,现在它可以正常工作了。谢谢你们试图帮助我

于 2013-02-13T11:52:30.953 回答