gpt4 book ai didi

php - 尝试从 MySQL 数据库中调用 longblob 信息以进行文件输入控制

转载 作者:行者123 更新时间:2023-11-29 21:38:56 25 4
gpt4 key购买 nike

各位程序员大家好,

我在网页设计方面相当新手,所以请以实物方式回复。我无法在任何论坛中找到针对我的独特问题的解决方案,因此我在这里提出我的问题。

我已经设置了 MySQL 数据库,可以很好地上传数据和图像。但是,我有一个管理员帐户,我希望能够通过网络表单编辑数据库中的信息。我尝试了很多方法来让表单从数据库中读取信息并自动填充表单,但是我无法让文件输入控件“记住”或调用已上传的图像。所有其他数据,例如 ID、名称等工作文件和自动填充,但不是图像。

这是我用来呈现和填写表单的一些代码。我强烈感觉错误出在 $row else 语句中。我不确定如何自动填充文件输入元素。我省略了部分内容,因为整个代码相当长(用省略号表示)。如果您需要更多信息,请与我们联系。任何想法或例子都会很棒。谢谢。

PS - 我知道 mysql_query 已被贬值...我稍后会修复它。

//runs when the form needs to display, retaining the values <- abbreviated to make shorter
function renderForm($id, $name, $image, $description, $salePrice, $listPrice, $shipping, $company, $category, $subCategory, $quantity, $type, $newArrival, $vintage, $error){
//if there are any errors...
if ($error != ''){
//display errors
echo "<div id=\"newMemberError\">$error</div>\n";
}

//display the form
echo "<form method=\"post\" enctype=\"multipart/form-data\">\n";
echo "<input type=\"hidden\" name=\"max_file_size\" value=\"6000000\">\n";
echo "<table id=\"newMemberTable\">\n";
echo "<tr>\n";
echo " <th><label>ID: <span class=\"aster\">*</span></label></th>\n";
echo " <td><input type=\"text\" name=\"id\" value=\"$id\"/></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo " <th><label>Name: <span class=\"aster\">*</span></label></th>\n";
echo " <td><input type=\"text\" name=\"name\" value=\"$name\"></td>\n";
echo "</tr>\n";
...
echo "<tr>\n";
echo " <th><label>Image: <span class=\"aster\">*</span></label></th>\n";
echo " <td><input type=\"file\" name=\"image\" value=\"data:image/$type;base64,$image\"></td>\n";
echo "</tr>\n";
echo "<tr><td><img class=\"paginatedImg\" height=\"40\" width=\"50\" src=\"data:image/$type;base64,$image\"></td></tr>\n";
echo "<tr>\n";
echo " <th><label>Type of Image: <span class=\"aster\">*</span></label></th>\n";
echo " <td><input type=\"text\" name=\"type\" value=\"$type\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo " <th>&nbsp;</th>\n";
echo " <td><input id=\"newMemberBtn\" type=\"submit\" name=\"submit\" value=\"Submit\"><span id=\"requiredMsg\">* required</span></td>\n";
echo "</table>\n";
echo "</form>\n";
}

//check if the form has been submitted. If it has, process the form and save it to the database
if(isset($_POST['submit'])){
...
}
//if the form hasn't been submitted, get the data from the database and display the form
else{
//get the id value from the URL (if it exists)
if (isset($_GET['id'])){
//query database
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM tbl WHERE id='$id'")
or die(mysql_error());
//set variable to hold amount of rows
$row = mysql_fetch_array($result);

//if the ID matches up with the database...
if($row){
//get the data from database
$id = $row['id'];
$name = $row['name'];
$image = $row['image'];
$description = $row['description'];
$salePrice = $row['salePrice'];
$listPrice = $row['listPrice'];
$shipping = $row['shipping'];
$company = $row['company'];
$category = $row['category'];
$subCategory = $row['subCategory'];
$quantity = $row['quantity'];
$type = $row['type'];
$newArrival = $row['newArrival'];
$vintage = $row['vintage'];

//display form
renderForm($id, $name, $image, $description, $salePrice, $listPrice, $shipping, $company, $category, $subCategory, $quantity, $type, $newArrival, $vintage, '');
}
//if no match...
else{
//display error message to user
echo "No results!";
}
}
//if the 'id' in the URL isn't valid, or if there is no 'id' value...
else{
//display error message to user
echo 'Error!';
}

}

最佳答案

您无法使用 input 标签显示图像,因为 value 属性不适用于 input[type=file]。请参阅http://www.w3.org/TR/html-markup/input.file.html 。但是,您可以在图像标签中显示图像:

echo "<img src=\"data:image/$type;base64,$image\" />";

关于php - 尝试从 MySQL 数据库中调用 longblob 信息以进行文件输入控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34697023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com