php - PHP / SQL Server:PHP注意:未定义索引:和PHP注意:未定义变量:
问题描述
我的系统有些奇怪。目前,我开发了一个系统,使用户可以通过从文件中选择并上传到数据库来更新照片。
问题是当我点击“请选择”选择照片并点击“上传”后,会显示“照片已更新!” 当我在该警报上单击“确定”时,它将显示:
PHP 通知:未定义索引:report_id 在 C:\inetpub\wwwroot\tgotworker_testing\pages\dashboard\engineer\view_task\view_task.php 第 7 行
PHP 注意:未定义的变量:C:\inetpub\wwwroot\tgotworker_testing\pages\dashboard\engineer\view_task\view_task.php 中的 report_date 在第 178 行
PHP 注意:未定义变量:C:\inetpub\wwwroot\tgotworker_testing\pages\dashboard\engineer\view_task\view_task.php 中的 ot_start 第 182 行
PHP 注意:未定义变量:C:\inetpub\wwwroot\tgotworker_testing\pages\dashboard\engineer\view_task\view_task.php 中的 ot_end 在第 185 行
......
但是,当我检查数据库时,照片更新了!我能知道为什么吗?
下面是我的代码。
<?php
require_once "../../../../config/configPDO.php";
require_once "../../../../config/check.php";
$team_n = $_SESSION['team_n'];
$report_id = $_GET['report_id'];
$sql = "SELECT * FROM ot_report LEFT JOIN ot_users ON ot_report.badgeid = ot_users.badgeid LEFT JOIN ot_team ON ot_team.team_id = ot_users.team_id WHERE report_id = :report_id";
$query = $conn->prepare($sql);
$query->execute(array(':report_id' => $report_id));
while($row = $query->fetch(PDO::FETCH_ASSOC)){
$report_id = $row["report_id"];
$report_date = $row["report_date"];
$task_name = $row["task_name"];
$photo_before = $row["photo_before"];
$photo_after = $row["photo_after"];
$ot_start = $row["ot_start"];
$ot_end = $row["ot_end"];
$time_photo_before = $row["time_photo_before"];
$time_photo_after = $row["time_photo_after"];
$report_status = $row["report_status"];
}
?>
<table align="center" width="100%">
<tr>
<td width="20%"><b>Date Report</b></td>
<td width="80%" colspan='3'><?php echo $report_date; ?></td>
</tr>
<tr>
<form action="update_task_name.php" method="POST">
<td><b>Task Name</b></td>
<td colspan = '2'><input type="text" class="form-control" name="task_name" value="<?php echo $task_name; ?>"/></td>
<input type="hidden" name="report_id" value="<?php echo $report_id ?>">
<td><input type="submit" class="btn btn-primary btn-block" value = "Save" onclick="confirm('Are you sure?')"></td>
</form>
</tr>
<form action="update_photo_before.php" method="post" id="form" enctype="multipart/form-data">
<tr>
<td rowspan = '3'><b>Before Task</b></td>
<?php
if(!isset($photo_before) || empty($photo_before)) {
echo "<td colspan='2' rowspan='2'><img src='../../../../images/faces/noimage.png'/></td>";
}else{
echo "<td colspan='2' rowspan='2'><img src='data:image/jpeg;base64,".$photo_before."'/></td>";
}
?>
<td colspan ='2'><input type="file" name="uploadFile" value="" /></td>
</tr>
<tr>
<input type="hidden" name="report_id" value="<?php echo $report_id ?>">
<td><input type="submit" name="submitBtn" value="Upload" onclick="confirm('Are you sure?')"/></td>
</tr>
</form>
<tr>
<?php
if($time_photo_before == null) {
$time_photo_before = " -";
}else{}
?>
<td colspan='3'><?php echo "Time: <b>" .$time_photo_before."</b>"; ?></td>
<tr>
<td rowspan = '3'><b>After Task</b></td>
<?php
if(!isset($photo_after) || empty($photo_after)) {
echo "<td colspan='2' rowspan='2'><img src='../../../../images/faces/noimage.png'/></td>";
}else{
echo "<td colspan='2' rowspan='2'><img src='data:image/jpeg;base64,".$photo_after."'/></td>";
}
?>
<td colspan ='2'></td>
</tr>
<tr>
<td></td>
</tr>
</tr>
<tr>
<?php
if($time_photo_after == null) {
$time_photo_after = " -";
}else{}
?>
<td colspan='3'><?php echo "Time: <b>" .$time_photo_after."</b>"; ?></td>
</tr>
<tr>
<td><b>OT - From</b></td>
<td><?php echo $ot_start; ?></td>
<form action="update_ot_start.php" method="POST">
<td width ='35%'>
<select class="form-control" id="exampleFormControlSelect1" name="ot_start">
<option value="12:00" <?php echo $ot_start == '12:00'? 'selected': '';?> >12:00</option>
<option value="12:30" <?php echo $ot_start == '12:30'? 'selected': '';?> >12:30</option>
<option value="13:00" <?php echo $ot_start == '13:00'? 'selected': '';?> >13:00</option>
</select>
<input type="hidden" name="report_id" value="<?php echo $report_id ?>">
</td>
<td width ='30%'><input type="submit" class="btn btn-primary btn-block" value = "Save" onclick="confirm('Are you sure?')"></td>
</form>
</tr>
<tr>
<td><b>OT - To</b></td>
<td width ='35%'><?php echo $ot_end; ?>
</td>
<form action="update_ot_end.php" method="POST">
<td width ='35%'>
<select class="form-control" id="exampleFormControlSelect1" name="ot_end">
<option value="15:30" <?php echo $ot_end == '15:30'? 'selected': '';?> >15:30</option>
<option value="16:00" <?php echo $ot_end == '16:00'? 'selected': '';?> >16:00</option>
</select>
<input type="hidden" name="report_id" value="<?php echo $report_id ?>">
</td>
<td width ='30%'><input type="submit" class="btn btn-primary btn-block" value = "Save" onclick="confirm('Are you sure?')"></td>
</form>
</tr>
<tr>
<td><b>Report Status</b></td>
<?php
if($report_status=="Pending")
{
$color="color:blue";
}
else
{
$color="color:green";
}
echo "<td style='$color' colspan='3'><strong>" . $report_status ."</strong></td>";
?>
</tr>
</table>
update_photo_before.php
<?php
require_once '../../../../config/configPDO.php';
if(isset($_FILES['uploadFile']['name']) && !empty($_FILES['uploadFile']['name'])) {
//Allowed file type
$allowed_extensions = array("jpg","jpeg","png","gif");
//File extension
$ext = strtolower(pathinfo($_FILES['uploadFile']['name'], PATHINFO_EXTENSION));
//Check extension
if(in_array($ext, $allowed_extensions)) {
//Convert image to base64
$encoded_image = base64_encode(file_get_contents($_FILES['uploadFile']['tmp_name']));
$encoded_image = $encoded_image;
$query = "UPDATE ot_report SET photo_before = '$encoded_image' WHERE report_id = :report_id";
$sql = $conn->prepare($query);
$sql->bindParam(':report_id', $_POST['report_id']);
$sql -> execute();
echo "File name : " . $_FILES['uploadFile']['name'];
echo "<br>";
if($sql->rowCount() > 0 ) {
echo "
<script>alert('Photo updated!')</script>
<script>window.location = 'view_task.php'</script>
";
$last_insert_id = $conn-> lastInsertId();
} else {
echo "
<script>alert('Fail to updated')</script>
<script>window.location = 'view_task.php'</script>
";
}
} else {
echo "File not allowed";
}
}
?>
解决方案
推荐阅读
- node.js - 什么是脚本在谷歌应用引擎上运行缓慢的一些原因?
- python-3.x - 数字的数字总和..TypeError:'int'对象不可调用
- excel - 从具有多个条件的列中提取唯一值
- spring - 春季启动注解@springbootapplication
- rust - 为什么 Command::output 阻塞的时间比它产生的子进程长?
- javascript - 在数百万条记录中搜索的最快方法是两个 js 对象的组合
- python - mysql.connector 在尝试连接到本地主机上的数据库时返回错误
- jquery - reactjs youtube视频自动播放可以在没有静音的情况下实现吗?
- amazon-web-services - AWS SSM 未被识别为命令
- asciidoc - 无法使用 asciidoctor-pdf 设置字体大小