我想将上传的图像显示到另一个页面,显示名字姓氏和与该上传对应的图像这是我目前拥有的代码,它显示了保存在文件夹中的所有图像我只想显示与信息相对应的最近上传的图像提交
<?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';
}
?>