我正在尝试更新一个也具有输入文件类型的页面,当我尝试更新该页面时,查询达到文件类型的值为空白时查询将不起作用,因为我不想更新它
<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_name
,brand_type
,brand_logo
,status
)VALUES('IFB','服务”,“在第1行
答案 0 :(得分:0)
将您的UPDATE
查询更改为
$sql = "UPDATE `brands` SET `brand_name` = '".$brandName ."', `brand_type` = '".$brandType."', `brand_logo` = '".$brandLogo ."', `status` = '" . $status ."' WHERE id = '" . $id . "'";