一旦满足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';
?>
您尚未为选项指定任何值;)
<option value="Resolved">Resolved</option>
PHP代码在表单提交之前执行,因此尚未定义$_POST[‘status’]。
$_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);
}
}
}
?>
您缺少一些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片段中遗漏了它,而在第二个html片段中有它,所以PHP没有任何东西可以得到
我将所有php移到了html表单的顶部,现在它工作得很好。感谢大家帮助我完成