如果图像已经在数据库中并且不再次更新,我们如何给出条件?

时间:2017-01-21 07:24:51

标签: javascript php jquery html5 css3

代码:

if($_FILES['logo']['name']!='')
{
    echo "<label for='Category_category_active' class='required'>University Logo</label>
           <input type='file' name='logo'  id='logoo'><span style='color:red;' disabled>Current Logo:</span>&nbsp;".$logo."";
}
else
{
    echo "<label for='Category_category_active' class='required'>University Logo</label>
          <input type='file' name='logo'  id='logoo'><span style='color:red;' disabled>Current Logo:</span>&nbsp;".$logo."";
}
if($_FILES['uni_image']['name']!='')
{
    echo "<label for='Category_category_active' class='required'>University Image</label>
          <input type='file' name='uni_image'  id='uni_image'><span style='color:red;' disabled>Current Image:</span>&nbsp; ".$uni_image."";
}
else
{
    echo "<label for='Category_category_active' class='required'>University Image</label>
          <input type='file' name='uni_image'  id='uni_image'><span style='color:red;' disabled>Current Image:</span>&nbsp; ".$uni_image."";
}

当我点击提交按钮文件时,图像名称不显示。那么如何检查数据库中是否已存在无法更新的文件映像名称。

1 个答案:

答案 0 :(得分:0)

处理你的逻辑。

尝试将您的步骤简化为简单的直接步骤。

您只是在不存在的情况下尝试更新图像。

步骤1.) 在帖子上,POST结果的查询数据库value。做一个(这个例子是pdo)

        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $sql = "SELECT * FROM DatabaseTableNameHere WHERE img_column_name = ?";
        $q= $pdo->prepare($sql);
        $q->execute(array($postvarvaluetovalidate));
        $data = $q->fetch(PDO::FETCH_ASSOC);

步骤2.)

if ($q->rowCount() > 0) { $error = 'msghere'; } else { continue insert into database code here }