簡體   English   中英

在PHP編輯頁面中更新輸入類型文件

[英]UPDATE input type file in PHP edit page

我正在嘗試更新一個也有輸入文件類型的頁面,當我嘗試更新頁面時,當它達到文件類型的值時,查詢將無效,因為我不想更新它。

<form method="post" id="form" action="edit.php" class="form-horizontal" enctype="multipart/form-data">
    <?php $result = mysqli_query($conn,"SELECT * FROM brands WHERE id='".$_GET['id']."'"); while($row = mysqli_fetch_array($result))
    {?>
    <label >Brand Name</label>
    <input type="text" name="brandName" id="brandName" value="<?php echo $row['brand_name'] ?>" required />
    <label class="col-md-3 control-label">Brand Type</label>
    <select data-plugin-selectTwo class="form-control populate" name="brandType" id="brandType">
            <option value="select" >Select an Option</option>
            <option value="Products" <?php if($row['brand_type'] == 'products') { ?> selected="selected"<?php } ?>>Products</option>
            <option value="Services" <?php if($row['brand_type'] == 'services') { ?> selected="selected"<?php } ?>>Services</option>
        </select>
    <label >Brand Logo</label>

    <img src="<?php echo ASSETS.$row['brand_logo'] ?>" max-width="200px"/>
        <input type="file" name="brandLogo"  id="brandLogo"/>
    <label class="col-md-3 control-label">Status</label>
    <select data-plugin-selectTwo class="form-control populate" name="status" id="status">
            <option value="select">Select an Option</option>
            <option value="ok" <?php if($row['status'] == 'ok') { ?> selected="selected"<?php } ?>>OK</option>
            <option value="pending" <?php if($row['status'] == 'pending') { ?> selected="selected"<?php } ?>>Pending</option>
            <option value="removed" <?php if($row['status'] == 'removed') { ?> selected="selected"<?php } ?>>Removed</option>
        </select>
    <?php }?>
        <button type="submit" id="submit" name="submit" class="btn btn-primary">Update</button>

我可以查看舊圖像,如果我不想更新它,那么我應該如何使用UPDATE查詢,我使用它的原因如下:

if(isset($_POST['submit']))
{
$brandName = $_POST['brandName'];
$brandType = $_POST['brandType'];
$brandLogo = "/images/".$_POST['brandLogo'];
$status = $_POST['status'];
$id = isset($_GET['id']) ? $_GET['id'] : '';

$sql = "UPDATE `brands` (`brand_name`, `brand_type`, `brand_logo`,  `status`)VALUES ('".$brandName."', '".$brandType."', '".$brandLogo."', '".$status."') WHERE id='".$id."'";


$result = mysqli_query($conn,$sql) or die(mysqli_error($conn));;
if($result){$msg = urlencode($brandName." has been updated");
header("Location: http://example.com/brands/index.php?added=".$brandName);
//echo "update";
}else{$msg = $brandName." cannot be updated.";
//echo "not update";
}
}

我沒有上傳圖片,只是添加了圖片網址。 是什么導致了這個問題?

這是我得到的錯誤你的SQL語法有錯誤; 檢查與您的MariaDB服務器版本對應的手冊,以便在'( brand_namebrand_typebrand_logostatus )附近使用正確的語法VALUES('IFB','Services','在第1行

將您的UPDATE查詢更改為

$sql = "UPDATE `brands` SET `brand_name` = '".$brandName ."', `brand_type` = '".$brandType."', `brand_logo` = '".$brandLogo ."', `status` = '" . $status ."' WHERE id = '" . $id . "'";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM