dst3605528 2015-03-16 07:19 采纳率: 0%
浏览 17

更新表单上的PHP文件上载

I have created a edit form as follows. I want to edit the uploaded file and it should be updated in the mysql db. While inserting a record file is uploading into the db but while editing a record its not uploading into db. Remaining fields are updating but file upload is not happening.

Can anybody help me to solve this issue?

Thanks in advance.

Edit.php

<?php
// include db connection.
    include 'dbconn.php';
    // If the form was submitted/posted, update the record.
    if($_POST)
{
    $path = '';
    $folder = "Folder/";
if (is_uploaded_file($_FILES['filename']['tmp_name']))
{   
if (move_uploaded_file($_FILES['filename']['tmp_name'], $folder.$_FILES['filename']['name'])) 
    {
    $path = $folder . $_FILES['filename']['name'];
    } 
    else 
    {
    $path = '';
    };
} 
else 
{
     $path = '';
};

        // write query.
        $sql = "UPDATE main SET category = ?, sd = ?, fd = ?, assignto = ?, reviewed = ?, upload = ? WHERE srn = ?";
        $stmt = $mysqli->prepare($sql);
        // Binding params.
        $stmt->bind_param('sssssbi',$_POST['category'],$_POST['sd'],$_POST['fd'],$_POST['assignto'],$_POST['reviewed'],$_POST['path'],$_POST['srn']);
        // Execute the update statement.
        if($stmt->execute())
        { ?>
        <script language="javascript">
        alert("Task updated successfully");
        top.location.href = "view.php"; // Page redirection.
        </script>
            // Close the prepared statement.
        <?php   $stmt->close();
}
        else 
        {
    die("Unable to update the task....");
        }
    }
$sql = "SELECT srn, client, type, fy, category, sd, fd, assignto, edoc, reviewed, upload FROM main WHERE srn = \"" . $mysqli->real_escape_string($_GET['srn']) . "\" LIMIT 0,1";
// Execute the sql query.
$result = $mysqli->query($sql);
// Get the result.
$row = $result->fetch_assoc();
// php's extract() makes $row['client'] to $client automatically.
extract($row);
// Disconnect from db.
$result->free();
$mysqli->close();
?>
<form action="Edit.php?srn=<?php echo $srn; ?>" method="POST" enctype="multipart/form-data" novalidate>
            <span>File upload</span>
<input type="hidden"name="MAX_FILE_SIZE" value="2000">
        <input name ="filename" type="file"/>

<button id='send' type='submit'>Update</button>
</form>

dbconn.php

<?php
// Set connection variables.
$host = "localhost";
$user = "root";
$pwd  = "root";
$db   = "eservice";
// Connect to mysql server
$mysqli = new mysqli($host,$user,$pwd,$db);
/* Check if any error occured */
if (mysqli_connect_errno()) 
{
  echo "Failed to connect to mysql : " . mysqli_connect_error();
   exit;
}
?>
  • 写回答

1条回答 默认 最新

  • dsfdsfsdf45489 2015-03-16 11:05
    关注

    Move the file upload code to go inside the if($_POST) code block.

    You are not checking if the $_FILES array exists before running any code on it.

    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行