在php中显示最近上传的图像,只显示与提交给该fie的其他数据相对应的单个图像


display recent uploaded image in php only display single image corresponding to the ther data submited to that fie

我想将上传的图像显示到另一个页面,显示名字、姓氏和与上传对应的图像这是我的代码,它当前显示保存在文件夹中的所有图像我只想显示与提交的信息对应的最近上传的图像

  <?php 
  $con = mysql_connect("localhost","username","pa…
 if (!$con)
 {
  die('Could not connect: ' . mysql_error());
   }
  mysql_select_db("database", $con);


   $sql="INSERT INTO nametable (fname, lname, mname, image, status, id)

           VALUES
        ('$_POST[fname]','$_POST[mname]','$_PO… 'display','')";
       if (!mysql_query($sql,$con))
                 {
             die('Error: ' . mysql_error());
                }
                     echo "";
                mysql_close($con);
                  ?>               <?php
            // Assigning value about your server to variables for database connection
        $hostname_connect= "localhost";
            $database_connect= "database";
                  $username_connect= "username";
            $password_connect= "password";
   $connect_solning = mysql_connect($hostname_connect, $username_connect, $password_connect) or      trigger_error(mysql_error(),E_USER_ERROR… 
    @mysql_select_db($database_connect) or die (mysql_error()); 
    if($_POST)
     { 
    // $_FILES["file"]["error"] is HTTP File Upload variables $_FILES["file"] "file" is the name              of input field you have in form tag.

                     if ($_FILES["file"]["error"] > 0)
           {
        // if there is error in file uploading 
               echo "Return Code: " . $_FILES["file"]["error"] . "
                ";

         }
           else
              {
          // check if file already exit in "images" folder.
            if (file_exists("images/" . $_FILES["file"]["name"]))
  {
         echo $_FILES["file"]["name"] . " already exists. ";
        }
   else
       { //move_uploaded_file function will upload your image. 
          if(move_uploaded_file($_FILES["file"]["t… . $_FILES["file"]["name"]))
        {
      // If file has uploaded successfully, store its name in data base
       $query_image = "insert into table";
     if(mysql_query($query_image))
      {
         echo "Stored in: " . "images/" . $_FILES["file"]["name"];
           }
           else
      {
        echo'';
    }
   }
          }


        }
           }
         ?>
        <html>
     <head>
             </head>
          <body>
           <p>First name: <?php echo $_POST["fname"]; ?><br></p>
             <p>Middle name: <?php echo $_POST["mname"]; ?><br></p>
                <p>Last name: <?php echo $_POST["lname"]; ?><br></p>

          </form>
         </body>
                </html> 
                <?php
       // Assigning value about your server to variables for database connection
         $hostname_connect= "localhost";
               $database_connect= "database";
                $username_connect= "username";
               $password_connect= "password";
    $connect_solning = mysql_connect($hostname_connect, $username_connect, $password_connect) or           trigger_error(mysql_error(),E_USER_ERROR… 
  @mysql_select_db($database_connect) or die (mysql_error()); 
             $query_image = "SELECT * FROM table";
           // This query will show you all images if you want to see only one image pass            id='$id' e.g. "SELECT * FROM nametable id='$id'".
    $result = mysql_query($query_image);
            if(mysql_num_rows($result) > 0)
         {
         while($row = mysql_fetch_array($result))
            {
              echo '<img width="165" height="104" border="0" src="images/'.$row["image"].'">';
              }
         }
              else
          {
             echo 'File name not found in database';
     }
    ?>
$query_image = "SELECT * FROM table order by id desc limit 1";