当我在php中更新任何其他字段(如名称和id图像)时,会自动变为空白吗?

当我在php中更新任何其他字段(如名称和id图像)时,会自动变为空白吗?,php,css,mysql,database,mysqli,Php,Css,Mysql,Database,Mysqli,当我每次更新表中的任何文件(如名称和id)时,在php和数据库表中,当我不更新图像时,图像自动变为空白!我把唯一的名字dj改为jd 在显示页面上的图像自动变为空白,有人能帮我处理这个php代码吗!! 在这里输入代码 <?php $link=mysqli_connect("localhost","root","","appoitement"); if(isset($_REQUEST["e1"]

当我每次更新表中的任何文件(如名称和id)时,在php和数据库表中,当我不更新图像时,图像自动变为空白!我把唯一的名字dj改为jd 在显示页面上的图像自动变为空白,有人能帮我处理这个php代码吗!! 在这里输入代码

<?php
$link=mysqli_connect("localhost","root","","appoitement");
if(isset($_REQUEST["e1"]))
    {
    $id1=$_REQUEST["id"];
    $v1=$_REQUEST["t1"];
    $v2=$_REQUEST["t2"];
    $v3=$_REQUEST["t3"];
    $v4=$_REQUEST["t4"];
    
    $fn=time().$_FILES["ph"]["name"];              
$qry2="update doctorregistration set name='$v1',mobile='$v2',email='$v3',age='$v4',photo='$fn' where id=".$id1;
    mysqli_query($link,$qry2);

if($_FILES["ph"]["size"]>0)
{
    move_uploaded_file($_FILES["ph"]["tmp_name"],"upload/$fn"); 
}
    header("location:profile.php");
}
        $qry="select * from doctorregistration where id=".$_SESSION["id"];
         $result=mysqli_query($link,$qry);
        if(mysqli_affected_rows($link)>0){
            $row=mysqli_fetch_assoc($result);
?>
        <form method="POST" enctype="multipart/form-data">
                                        
        <input type="hidden" name="id" value="<?php echo $row["id"]; ?>"><br>   
        name::  <input type="text" name="t1" value="<?php echo $row["name"]; ?>"><br>
        mobile::    <input type="text" name="t2" value="<?php echo $row["mobile"]; ?>"><br>
        email::<input type="text" name="t3" value="<?php echo $row["email"]; ?>"><br>
        age::<input type="text" name="t4" value="<?php echo $row["age"]; ?>"><br>   
        Photo:: <input type="file" name="ph" value="<?php echo $row["photo"]; ?>"><br>
         <input type="submit" name="e1" value="update">
        </form>
         <?php
                }
        ?>
        <?php
               $link=mysqli_connect("localhost","root","","appoitement");
                $qry="select * from doctorregistration where id=".$_SESSION["id"];
                $result=mysqli_query($link,$qry);
                if(mysqli_affected_rows($link)>0)
                {
                $i=0;
                while($row=mysqli_fetch_assoc($result))
                {   
                 ?>
<hr>
<h2 class="text-center">Doctor</h2>
<hr>

<table class="table table-borderless" style="align:center">
  <tbody> 
    <tr>
      <th class="text-center" scope="col">Name</th>
      <td class="text-center"scope="col"><?php echo $row['name'];?></td>
    </tr>
    <tr>
      <th class="text-center" scope="col">email</th>
      <td class="text-center"scope="col"><?php echo $row["email"] ?></td>
    </tr>
    <tr>
      <th class="text-center" scope="col">Contact Number</th>
      <td class="text-center"scope="col"><?php echo $row['mobile'];?></td>
    </tr>
    <tr>
      <th class="text-center" scope="col">Age</th>
      <td class="text-center"scope="col"><?php echo $row['age'];?></td>
    </tr>   
    <th class="text-center" scope="col">photo</th>
      <td class="text-center"scope="col"><img src="upload/<?php echo $row["photo"]; ?>"></td>
    </tr>
  </tbody>
 </table>


 <?php
$i++;}
}
?> 

因此,如果确实上载了图像,请确保仅在SQL语句中包含图像字段。您可以使用if语句分部分构建SQL,以决定要将哪些部分添加到string.P.s中。另外,您还需要紧急阅读并修复代码,因为目前这是一场即将发生的安全灾难,而且,在更基本的层面上,任何人只要在其中一个输入字段中添加一个撇号,就可以破坏您的查询!警告:您完全可以使用参数化的预处理语句,而不是手动生成查询。它们由或提供。永远不要相信任何形式的输入!即使您的查询仅由受信任的用户执行。