简体   繁体   English

PHP-文件编辑表单显示空白

[英]PHP - file edit form shows blank

I wanted to make an edit file form where you choose the a different file to upload and replace the previous file. 我想制作一个编辑文件表单,从中选择一个不同的文件上载并替换上一个文件。 This is my code. 这是我的代码。

<?php
require("config.php");
$id = $_GET['id'];

$sql = "SELECT * FROM contracts WHERE id= '$id'";
$result = $con->query($sql);
while ($row = $result->fetch_assoc())
{   
?>

<html><head></head>
<body>

<form method="GET" action="" enctype="multipart/form-data">

    ID: <?php echo $id; ?><br>
    <input type="hidden" name="id" value="<?php echo $id; ?>" />

    Upload File:
    <input type="file" name="upload" value="<?php echo $row($_FILES['name']) ?>"/><br>  
    <input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>

<?php
}

if(isset($_GET['edit'])  ){


if ($_FILES['upload']['size'] != 0 ){

$filename = $con->real_escape_string($_FILES['upload']['name']);
$filedata= $con->real_escape_string(file_get_contents($_FILES['upload']['tmp_name']));
$filetype = $con->real_escape_string($_FILES['upload']['type']);
$filesize = intval($_FILES['upload']['size']);

$query = "UPDATE `contracts` set `filename` = '$filename',`filedata` = '$filedata', `filetype` = '$filetype',`filesize` = '$filesize' WHERE `id` = '$id' " ;

if ($con->query($query) == TRUE) {
echo "<br><br> New record created successfully";
} else {
    echo "Error:<br>" . $con->error;
}

} else {

$filename = $con->real_escape_string($_FILES['upload']['name']);
$filetype = $con->real_escape_string($_FILES['upload']['type']);
$filesize = intval($_FILES['upload']['size']);

$query = "UPDATE `contracts` set `filename` = '$filename', `filetype` = '$filetype',`filesize` = '$filesize' WHERE `id` = '$id' " ;

if ($con->query($query) == TRUE) {
echo "<br><br> New record created successfully";
} else {
echo "Error:<br>" . $con->error;
}

}
$con->close(); 
}   

?>

When I went to the page it only shows blank. 当我转到页面时,它仅显示空白。 Like this 像这样 编辑文件错误

Can someone tell me what did I do wrong? 有人可以告诉我我做错了什么吗?

The correct coding should be 正确的编码应为

Upload File:
    <?php echo $row['filename'] ?>
    <input type="file" name="upload"/><br>  
    <input type="submit" name="edit" value="Submit"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM