简体   繁体   English

在PHP编辑页面中更新输入类型文件

[英]UPDATE input type file in PHP edit page

I am trying to update a page which also have an input file type and when I try to update the page the query won't work when it reaches the value of file type which is blank as I do not want to update it. 我正在尝试更新一个也有输入文件类型的页面,当我尝试更新页面时,当它达到文件类型的值时,查询将无效,因为我不想更新它。

<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>

I can view the old image and if I do not want to update it then how should I use the UPDATE query, what I am using it faulty as follows: 我可以查看旧图像,如果我不想更新它,那么我应该如何使用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";
}
}

I am not uploading the image yet just adding the image url. 我没有上传图片,只是添加了图片网址。 Is that what is causing the problem? 是什么导致了这个问题?

This is the error I am getting You have an error in your SQL syntax; 这是我得到的错误你的SQL语法有错误; check the manual that corresponds to your MariaDB server version for the right syntax to use near '( brand_name , brand_type , brand_logo , status )VALUES ('IFB', 'Services', ' at line 1 检查与您的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