你好遵循程序員,想有從MySQL數據庫形式召回LONGBLOB信息文件輸入控制
我是相當新手在網頁設計,所以請以實物響應。我無法在任何論壇上找到解決我的獨特問題的解決方案,所以我在這裏問我的問題。
我有一個MySQL數據庫設置,並可以上傳數據和圖像很好。但是,我有一個管理員帳戶,我希望能夠通過Web表單編輯數據庫中的信息。我已經嘗試了很多方式來獲取表單從數據庫中讀取信息並自動填充表單,但是我無法讓文件輸入控件「記住」或回想上傳的圖像。所有其他數據,如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> </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!';
}
}
其實我這樣做,在提交表格後顯示數據。所有記錄都顯示已輸入。問題在於,如果管理員想要編輯一個條目,除了圖像以外,所有的數據都會被重新調用,要求他們再次上傳它...我試圖阻止這種情況,特別是因爲有很多條目需要保留跟蹤,這是多餘的,管理員可能無法訪問他們正在使用的設備上的圖像。 – Potzero
我明白了。你可以更新你的PHP上傳處理程序,以保持現有的圖像,當沒有新的圖像發佈。 – Fabricator