我的表单中已经有一个单独的文件上传输入字段。但我也想要多个文件输入。我尝试了很多方法来添加多个文件上传的输入字段并在我的表单中显示代码,但似乎我的错误是我无法做到这一点。
我有多个文件代码,但如果有人可以帮我将其整合到我的表单中,请。我的添加和编辑表单是一样的。并请帮助我如何显示上传的多个图像。我真的不明白,就像在表格中输入一行一样,那么多个图像怎么能显示出来呢?
下面是我的代码:
edit.php
是我的表格multiple.php
和display.php
文件包含代码。edit.php
<!DOCTYPE html>
<html dir="ltr" lang="en-US"><head><!-- Created by Artisteer v4.0.0.58475 -->
<meta charset="utf-8">
<title>library</title>
<meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width">
<link href='https://sites.google.com/site/99webdemos/favicon.png' rel='shortcut icon' type='image/x-icon'/>
<!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<link rel="stylesheet" href="css/style.css" media="screen">
<!--[if lte IE 7]><link rel="stylesheet" href="style.ie7.css" media="screen" /><![endif]-->
<link rel="stylesheet" href="css/style.responsive.css" media="all">
<script src="js/jquery.js"></script>
<script src="js/script.js"></script>
<script src="js/script.responsive.js"></script>
<script type="text/javascript" language="JavaScript">
jQuery(document).ready(function()
{
jQuery(".form-message").fadeOut(10000);
});
</script>
<style>.art-content .art-postcontent-0 .layout-item-0 { padding-right: 10px;padding-left: 10px; }
.ie7 .post .layout-cell {border:none !important; padding:0 !important; }
.ie6 .post .layout-cell {border:none !important; padding:0 !important; }
</style></head>
<body>
<div id="art-main">
<div id="art-header-bg" class="clearfix">
</div>
<div id="art-hmenu-bg" class="art-bar art-nav clearfix">
</div>
<div class="art-sheet clearfix">
<header class="art-header clearfix">
<div class="art-shapes">
<h1 class="art-headline" data-left="0.5%">
<a href="http://www.99demos.blogspot.com" target="_blank">library</a>
</h1>
<h2 class="art-slogan" data-left="87.05%"><a href="http://99demos.blogspot.in/2014/06/createreadupdate-delete-with-image.html"></a></h2>
</div>
<nav class="art-nav clearfix">
<div class="art-nav-inner">
<ul class="art-hmenu"><li><a href="index.php" class="active">Home</a></li></ul>
</div>
</nav>
</header>
<div class="art-layout-wrapper clearfix">
<div class="art-content-layout">
<div class="art-content-layout-row">
<div class="art-layout-cell art-content clearfix"><article class="art-post art-article">
<h2 class="art-postheader">customer form</h2>
<div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout">
<div class="art-content-layout-row">
<div class="art-layout-cell layout-item-0" style="width: 100%" >
<br>
<?php
ob_start();
include('include/connect.php');
if(isset($_GET['id']))
{
$qry = "SELECT * FROM tbl_emp where id=".$_GET['id'];
$result = mysql_query($qry,$conn);
while($row = mysql_fetch_array($result));
{
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$name = $_POST["name"];
$age = $_POST["age"];
$gender=$_POST['gender'];
$martial = $_POST["martial"];
$contact = $_POST["contact"];
$email = $_POST["email"];
$location= $_POST["location"];
$category= $_POST["category"];
IF($_FILES['file']['name']!='')
{
$file='uploads/'.$row['image'];
@unlink($file);
$tmp_name = $_FILES["file"]["tmp_name"];
$namefile = $_FILES["file"]["name"];
$ext = end(explode(".", $namefile));
$image_name=time().".".$ext;
$fileUpload = move_uploaded_file($tmp_name,"uploads/".$image_name);
}
else
{
$image_name=$row['image'];
}
$sqlAdd ="update tbl_emp set name='".$name."', age='".$age."', gender='".$gender."', martial='".$martial."', contact='".$contact."', email='".$email."', location='".$location."', category='".$category."', image='".$image_name."' where id=".$_GET['id'];
mysql_query($sqlAdd);
header("Location:add.php?id=".@$_GET['id']."&msg=success");
exit;
} }
}
else
{
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$name = $_POST["name"];
$age = $_POST["age"];
$gender=$_POST['gender'];
$martial = $_POST["martial"];
$contact = $_POST["contact"];
$email = $_POST["email"];
$location= $_POST["location"];
$category= $_POST["category"];
IF($_FILES['file']['name']!='')
{
$tmp_name = $_FILES["file"]["tmp_name"];
$namefile = $_FILES["file"]["name"];
$ext = end(explode(".", $namefile));
$image_name=time().".".$ext;
$fileUpload = move_uploaded_file($tmp_name,"uploads/".$image_name);
}
$sqlAdd = mysql_query("insert into tbl_emp(name,age,gender,martial,contact,email,location,category,image) VALUES('$name','$age','$gender','$martial','$contact','$email','$location','$category','$image_name')");
header("Location:index.php?msg=success");
exit;
}
}
ob_end_flush();
if(isset($_GET['msg']))
{
?>
<div style="color:red;padding-bottom:10px;" class="form-message" align="center"><b>Task completd successfully.</b></div>
<?php
}
?>
<form method="post" name="login" id="login" enctype="multipart/form-data">
<table class="table" width="100%">
<tr>
<td width="10%">Customer Details</td>
<td></td>
</tr>
<tr>
<td width="10%">Full Name</td>
<td><input name="name" type="text" placeholder="Firstname Lastname" pattern="[A-Za-z-0-9]+\s[A-Za-z-'0-9]+" required value="<?php echo @$row['name'];?>"></td>
</tr>
<tr>
<td width="20%">Age</td>
<td><input name="age" type="text" value="<?php echo @$row['2'];?>" ></td>
</tr>
<tr>
<td>Gender</td>
<td><input type="Radio" name="gender" value="male" <?php if ($gender=='male') { echo 'checked'; } ?> />
Male
<input type="Radio" name="gender" value="female" <?php if ($gender=='female') { echo 'checked'; } ?> />
Female</td>
</tr>
<tr>
<td width="10%">Martial Status</td>
<td><input name="martial" type="text" value="<?php echo @$row['4'];?>" ></td>
</tr>
<tr>
<td width="20%">Contact Number</td>
<td><input name="contact" type="text" value="<?php echo @$row['5'];?>"></td>
</tr>
<tr>
<td width="10%">Email Address</td>
<td><input name="email" type="text" value="<?php echo @$row['6'];?>"></td>
</tr>
<tr>
<td width="10%">Location</td>
<td><input name="location" type="text" value="<?php echo @$row['7'];?>" ></td>
</tr>
<tr>
<td width="10%">category</td>
<td>
<select name="category" id="category" value="<?php echo @$row['11'];?>">
<option <?php if ($category== '1' ) echo 'selected="selected'; ?> value="1">1</option>
<option <?php if ($category== '2' ) echo 'selected="selected'; ?> value="2">2</option>
<option <?php if ($category== '3' ) echo 'selected="selected'; ?> value="3">3</option>
</select>
</td>
</tr>
<tr>
<td width="10%">Image</td>
<td><input name="file" type="file" multiple="" ></td>
</tr>
<?php
if(isset($row['image']))
{
?>
<tr>
<td> </td>
<td><img src="uploads/<?php echo $row['image'];?> " height="50" width="50"></td>
</tr>
<?php
}
?>
<tr>
<td> </td>
<td>
<input name="submit" value="Submit" type="submit" class="submit">
<input name="submit" value="Cancel" type="button" class="submit" onClick="window.location='index.php'">
</td>
</tr>
</table>
</form>
<a href="http://dme-medical.com/library/search.php">Go back to list</a>
</div>
</div>
</div>
</div>
</article></div>
</div>
</div>
</div>
</div>
<footer class="art-footer clearfix">
<div class="art-footer-inner">
<p>Copyright © 2016. All Rights Reserved.</p>
<p class="art-page-footer">
</p>
</div>
</footer>
</div>
</body></html>
&#13;
multiple.php
<?php
if(isset($_POST['submit'])){
if(count($_FILES['upload']['name']) > 0){
//Loop through each file
for($i=0; $i<count($_FILES['upload']['name']); $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['upload']['tmp_name'][$i];
//Make sure we have a filepath
if($tmpFilePath != ""){
//save the filename
$shortname = $_FILES['upload']['name'][$i];
//save the url and the file
$filePath = "uploaded/" . date('d-m-Y-H-i-s').'-'.$_FILES['upload']['name'][$i];
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $filePath)) {
$files[] = $shortname;
//insert into db
//use $shortname for the filename
//use $filePath for the relative url to the file
}
}
}
}
//show success message
echo "<h1>Uploaded:</h1>";
if(is_array($files)){
echo "<ul>";
foreach($files as $file){
echo "<li>$file</li>";
}
echo "</ul>";
}
}
?>
<form action="" enctype="multipart/form-data" method="post">
<div>
<label for='upload'>Add Attachments:</label>
<input id='upload' name="upload[]" type="file" multiple="multiple" />
</div>
<p><input type="submit" name="submit" value="Submit"></p>
</form>
Display.php的
<?php
$files = glob("uploaded/*.*");
for ($i=1; $i<count($files); $i++)
{
$image = $files[$i];
print $image ."<br />";
echo '<img src="'.$image .'" alt="Random image" height="300px" width="300px"/>'."<br /><br />";
}
?>
&#13;
答案 0 :(得分:0)
好的,这是 edit.php ,它应该处理多个文件,并且还会注意以前未序列化的数据...
<!DOCTYPE html>
<html dir="ltr" lang="en-US"><head><!-- Created by Artisteer v4.0.0.58475 -->
<meta charset="utf-8">
<title>library</title>
<meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width">
<link href='https://sites.google.com/site/99webdemos/favicon.png' rel='shortcut icon' type='image/x-icon'/>
<!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<link rel="stylesheet" href="css/style.css" media="screen">
<!--[if lte IE 7]><link rel="stylesheet" href="style.ie7.css" media="screen" /><![endif]-->
<link rel="stylesheet" href="css/style.responsive.css" media="all">
<script src="js/jquery.js"></script>
<script src="js/script.js"></script>
<script src="js/script.responsive.js"></script>
<script type="text/javascript" language="JavaScript">
jQuery(document).ready(function()
{
jQuery(".form-message").fadeOut(10000);
});
</script>
<style>.art-content .art-postcontent-0 .layout-item-0 { padding-right: 10px;padding-left: 10px; }
.ie7 .post .layout-cell {border:none !important; padding:0 !important; }
.ie6 .post .layout-cell {border:none !important; padding:0 !important; }
</style></head>
<body>
<div id="art-main">
<div id="art-header-bg" class="clearfix">
</div>
<div id="art-hmenu-bg" class="art-bar art-nav clearfix">
</div>
<div class="art-sheet clearfix">
<header class="art-header clearfix">
<div class="art-shapes">
<h1 class="art-headline" data-left="0.5%">
<a href="http://www.99demos.blogspot.com" target="_blank">library</a>
</h1>
<h2 class="art-slogan" data-left="87.05%"><a href="http://99demos.blogspot.in/2014/06/createreadupdate-delete-with-image.html"></a></h2>
</div>
<nav class="art-nav clearfix">
<div class="art-nav-inner">
<ul class="art-hmenu"><li><a href="index.php" class="active">Home</a></li></ul>
</div>
</nav>
</header>
<div class="art-layout-wrapper clearfix">
<div class="art-content-layout">
<div class="art-content-layout-row">
<div class="art-layout-cell art-content clearfix"><article class="art-post art-article">
<h2 class="art-postheader">customer form</h2>
<div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout">
<div class="art-content-layout-row">
<div class="art-layout-cell layout-item-0" style="width: 100%" >
<br>
<?php
ob_start();
include('include/connect.php');
if(isset($_GET['id']))
{
$qry = "SELECT * FROM tbl_emp where id=".$_GET['id'];
$result = mysql_query($qry,$conn);
while($row = mysql_fetch_array($result));
{
$row['image'] = @unserialize($row['image']);
if(!is_array($row['image'])) $row['image'] = array($row['image']);
if($_SERVER["REQUEST_METHOD"] == "POST")
{
//always always always always escape...
$name = mysql_real_escape_string($_POST["name"]);
$age = mysql_real_escape_string($_POST["age"]);
$gender= mysql_real_escape_string($_POST['gender']);
$martial = mysql_real_escape_string($_POST["martial"]);
$contact = mysql_real_escape_string($_POST["contact"]);
$email = mysql_real_escape_string($_POST["email"]);
$location= mysql_real_escape_string($_POST["location"]);
$category= mysql_real_escape_string($_POST["category"]);
$files = array();
if(count($_FILES['file']['name']) > 0){
//Loop through each file
foreach($_FILES['file']['error'] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
//Get the temp file path
$tmpFilePath = $_FILES['file']['tmp_name'][$i];
//Make sure we have a filepath
if($tmpFilePath != ""){
//save the filename
$shortname = date('d-m-Y-H-i-s').'-'.$_FILES['file']['name'][$i];
//save the url and the file
$filePath = "uploaded/" . $shortname;
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $filePath)) {
$files[] = $shortname;
//insert into db
//use $shortname for the filename
//use $filePath for the relative url to the file
}
}
}
}
}
If(!empty($files)) {
//get data ready for insertion
$allFiles = mysql_real_escape_string(serialize($files));
//remove old files
if(!empty($row['image'])) foreach($row['image'] as $oldFile) {
if(file_exists('uploaded/'.$oldFile)) unlink('uploaded/'.$oldFile);
}
}
else {
if(!is_array($row['image'])) $row['image'] = array($row['image']);
$allFiles = mysql_real_escape_string(serialize($row['image']));
}
$sqlAdd ="update tbl_emp set name='".$name."', age='".$age."', gender='".$gender."', martial='".$martial."', contact='".$contact."', email='".$email."', location='".$location."', category='".$category."', image='".$image_name."' where id=".$_GET['id'];
mysql_query($sqlAdd);
header("Location:add.php?id=".(int) @$_GET['id']."&msg=success");
exit;
}
}
}
else
{
if($_SERVER["REQUEST_METHOD"] == "POST")
{
//always always always always escape...
$name = mysql_real_escape_string($_POST["name"]);
$age = mysql_real_escape_string($_POST["age"]);
$gender= mysql_real_escape_string($_POST['gender']);
$martial = mysql_real_escape_string($_POST["martial"]);
$contact = mysql_real_escape_string($_POST["contact"]);
$email = mysql_real_escape_string($_POST["email"]);
$location= mysql_real_escape_string($_POST["location"]);
$category= mysql_real_escape_string($_POST["category"]);
$files = array();
if(count($_FILES['file']['name']) > 0){
//Loop through each file
foreach($_FILES['file']['error'] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
//Get the temp file path
$tmpFilePath = $_FILES['file']['tmp_name'][$i];
//Make sure we have a filepath
if($tmpFilePath != ""){
//save the filename
$shortname = date('d-m-Y-H-i-s').'-'.$_FILES['file']['name'][$i];
//save the url and the file
$filePath = "uploaded/" . $shortname;
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $filePath)) {
$files[] = $shortname;
//insert into db
//use $shortname for the filename
//use $filePath for the relative url to the file
}
}
}
}
}
If(!empty($files)) {
$allFiles = mysql_real_escape_string(serialize($files));
$result = mysql_query("INSERT INTO `tbl_emp` (`name`,`age`,`gender`,`martial`,`contact`,`email`,`location`,`category`,`image`) VALUES('$name','$age','$gender','$martial','$contact','$email','$location','$category','$image_name')") ? "success":"failure";
header("Location:index.php?msg=$result");
exit;
}
}
}
ob_end_flush();
if(isset($_GET['msg']))
{
?>
<div style="color:red;padding-bottom:10px;" class="form-message" align="center"><b>Task completd successfully.</b></div>
<?php
}
?>
<form method="post" name="login" id="login" enctype="multipart/form-data">
<table class="table" width="100%">
<tr>
<td width="10%">Customer Details</td>
<td></td>
</tr>
<tr>
<td width="10%">Full Name</td>
<td><input name="name" type="text" placeholder="Firstname Lastname" pattern="[A-Za-z-0-9]+\s[A-Za-z-'0-9]+" required value="<?php echo @$row['name'];?>"></td>
</tr>
<tr>
<td width="20%">Age</td>
<td><input name="age" type="text" value="<?php echo @$row['2'];?>" ></td>
</tr>
<tr>
<td>Gender</td>
<td><input type="Radio" name="gender" value="male" <?php if ($gender=='male') { echo 'checked'; } ?> />
Male
<input type="Radio" name="gender" value="female" <?php if ($gender=='female') { echo 'checked'; } ?> />
Female</td>
</tr>
<tr>
<td width="10%">Martial Status</td>
<td><input name="martial" type="text" value="<?php echo @$row['4'];?>" ></td>
</tr>
<tr>
<td width="20%">Contact Number</td>
<td><input name="contact" type="text" value="<?php echo @$row['5'];?>"></td>
</tr>
<tr>
<td width="10%">Email Address</td>
<td><input name="email" type="text" value="<?php echo @$row['6'];?>"></td>
</tr>
<tr>
<td width="10%">Location</td>
<td><input name="location" type="text" value="<?php echo @$row['7'];?>" ></td>
</tr>
<tr>
<td width="10%">category</td>
<td>
<select name="category" id="category" value="<?php echo @$row['11'];?>">
<option <?php if ($category== '1' ) echo 'selected="selected'; ?> value="1">1</option>
<option <?php if ($category== '2' ) echo 'selected="selected'; ?> value="2">2</option>
<option <?php if ($category== '3' ) echo 'selected="selected'; ?> value="3">3</option>
</select>
</td>
</tr>
<tr>
<td width="10%">Image</td>
<td><input name="file[]" type="file" multiple="" ></td>
</tr>
<?php
if(!is_array($row['image'])) $row['image'] = array($row['image']);
if(!empty($row['image']))
{
?>
<tr>
<td> </td>
<td>
<?php foreach($image as $row['image']): ?>
<img src="uploads/<?=$image;?> " height="50" width="50">
<?php endforeach; ?>
</td>
</tr>
<?php
}
?>
<tr>
<td> </td>
<td>
<input name="submit" value="Submit" type="submit" class="submit">
<input name="submit" value="Cancel" type="button" class="submit" onClick="window.location='index.php'">
</td>
</tr>
</table>
</form>
<a href="http://dme-medical.com/library/search.php">Go back to list</a>
</div>
</div>
</div>
</div>
</article></div>
</div>
</div>
</div>
</div>
<footer class="art-footer clearfix">
<div class="art-footer-inner">
<p>Copyright © 2016. All Rights Reserved.</p>
<p class="art-page-footer">
</p>
</div>
</footer>
</div>
</body></html>
答案 1 :(得分:0)
<!----------------New Code ---------------------->
<!DOCTYPE html>
<html dir="ltr" lang="en-US"><head><!-- Created by Artisteer v4.0.0.58475 -->
<meta charset="utf-8">
<title>library</title>
<meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width">
<link href='https://sites.google.com/site/99webdemos/favicon.png' rel='shortcut icon' type='image/x-icon'/>
<!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<link rel="stylesheet" href="css/style.css" media="screen">
<!--[if lte IE 7]><link rel="stylesheet" href="style.ie7.css" media="screen" /><![endif]-->
<link rel="stylesheet" href="css/style.responsive.css" media="all">
<script src="js/jquery.js"></script>
<script src="js/script.js"></script>
<script src="js/script.responsive.js"></script>
<script type="text/javascript" language="JavaScript">
jQuery(document).ready(function()
{
jQuery(".form-message").fadeOut(10000);
});
</script>
<script language="javascript" type="text/javascript">
window.onload = function () {
var fileUpload = document.getElementById("fileupload");
fileUpload.onchange = function () {
if (typeof (FileReader) != "undefined") {
var dvPreview = document.getElementById("dvPreview");
dvPreview.innerHTML = "";
var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.jpg|.jpeg|.gif|.png|.bmp)$/;
for (var i = 0; i < fileUpload.files.length; i++) {
var file = fileUpload.files[i];
if (regex.test(file.name.toLowerCase())) {
var reader = new FileReader();
reader.onload = function (e) {
var img = document.createElement("IMG");
img.height = "100";
img.width = "100";
img.src = e.target.result;
dvPreview.appendChild(img);
}
reader.readAsDataURL(file);
} else {
alert(file.name + " is not a valid image file.");
dvPreview.innerHTML = "";
return false;
}
}
} else {
alert("This browser does not support HTML5 FileReader.");
}
}
};
</script>
<style>.art-content .art-postcontent-0 .layout-item-0 { padding-right: 10px;padding-left: 10px; }
.ie7 .post .layout-cell {border:none !important; padding:0 !important; }
.ie6 .post .layout-cell {border:none !important; padding:0 !important; }
</style></head>
<body>
<div id="art-main">
<div id="art-header-bg" class="clearfix">
</div>
<div id="art-hmenu-bg" class="art-bar art-nav clearfix">
</div>
<div class="art-sheet clearfix">
<header class="art-header clearfix">
<div class="art-shapes">
<h1 class="art-headline" data-left="0.5%">
<a href="http://www.99demos.blogspot.com" target="_blank">library</a>
</h1>
<h2 class="art-slogan" data-left="87.05%"><a href="http://99demos.blogspot.in/2014/06/createreadupdate-delete-with-image.html"></a></h2>
</div>
<nav class="art-nav clearfix">
<div class="art-nav-inner">
<ul class="art-hmenu"><li><a href="index.php" class="active">Home</a></li></ul>
</div>
</nav>
</header>
<div class="art-layout-wrapper clearfix">
<div class="art-content-layout">
<div class="art-content-layout-row">
<div class="art-layout-cell art-content clearfix"><article class="art-post art-article">
<h2 class="art-postheader">customer form</h2>
<div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout">
<div class="art-content-layout-row">
<div class="art-layout-cell layout-item-0" style="width: 100%" >
<br>
<?php
ob_start();
include('include/connect.php');
if(isset($_GET['id']))
{
$qry = "SELECT * FROM tbl_emp where id=".$_GET['id'];
$result = mysql_query($qry);
$row = mysql_fetch_array($result);
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$name = $_POST["name"];
$age = $_POST["age"];
$gender=$_POST['gender'];
$martial = $_POST["martial"];
$contact = $_POST["contact"];
$email = $_POST["email"];
$location= $_POST["location"];
$drname= $_POST["drname"];
$cname= $_POST["cname"];
$clocation= $_POST["clocation"];
$implants=implode(',',$_POST['implants']);
$problem= $_POST["problem"];
$tgiven= $_POST["tgiven"];
$tdate= $_POST["tdate"];
IF($_FILES['file']['name']!='')
{
$file='uploads/'.$row['image'];
@unlink($file);
$tmp_name = $_FILES["file"]["tmp_name"];
$namefile = $_FILES["file"]["name"];
$ext = end(explode(".", $namefile));
$image_name=time().".".$ext;
$fileUpload = move_uploaded_file($tmp_name,"uploads/".$image_name);
}
else
{
$image_name=$row['image'];
}
$sqlAdd ="update tbl_emp set name='".$name."', age='".$age."', gender='".$gender."', martial='".$martial."', contact='".$contact."', email='".$email."', location='".$location."', drname='".$drname."', cname='".$cname."', clocation='".$clocation."', implants='".$implants."', problem='".$problem."', tgiven='".$tgiven."', tdate='".$tdate."', image='".$image_name."' where id=".$_GET['id'];
mysql_query($sqlAdd);
header("Location:add.php?id=".@$_GET['id']."&msg=success");
exit;
}
}
else
{
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$name = $_POST["name"];
$age = $_POST["age"];
$gender=$_POST['gender'];
$martial = $_POST["martial"];
$contact = $_POST["contact"];
$email = $_POST["email"];
$location= $_POST["location"];
$drname= $_POST["drname"];
$cname= $_POST["cname"];
$clocation= $_POST["clocation"];
$implants= $_POST["implants"];
$problem= $_POST["problem"];
$tgiven= $_POST["tgiven"];
$tdate= $_POST["tdate"];
IF($_FILES['file']['name']!='')
{
$tmp_name = $_FILES["file"]["tmp_name"];
$namefile = $_FILES["file"]["name"];
$ext = end(explode(".", $namefile));
$image_name=time().".".$ext;
$fileUpload = move_uploaded_file($tmp_name,"uploads/".$image_name);
}
$sqlAdd = mysql_query("insert into tbl_emp(name,age,gender,martial,contact,email,location,drname,cname,clocation,implants,problem,tgiven,tdate,image) VALUES('$name','$age','$gender','$martial','$contact','$email','$location','$drname','$cname','$clocation','$implants','$problem','$tgiven','$tdate','$image_name')");
header("Location:index.php?msg=success");
exit;
}
}
ob_end_flush();
if(isset($_GET['msg']))
{
?>
<div style="color:red;padding-bottom:10px;" class="form-message" align="center"><b>Task completd successfully.</b></div>
<?php
}
?>
<form method="post" name="login" id="login" enctype="multipart/form-data">
<table class="table" width="100%">
<tr>
<td width="10%">Customer Details</td>
<td></td>
</tr>
<tr>
<td width="10%">Full Name</td>
<td><input name="name" type="text" placeholder="Firstname Lastname" pattern="[A-Za-z-0-9]+\s[A-Za-z-'0-9]+" required value="<?php echo @$row['name'];?>"></td>
</tr>
<tr>
<td width="20%">Age</td>
<td><input name="age" type="text" value="<?php echo @$row['2'];?>" ></td>
</tr>
<tr>
<td>Gender</td>
<td><input type="Radio" name="gender" value="male" <?php if ($gender=='male') { echo 'checked'; } ?> />
Male
<input type="Radio" name="gender" value="female" <?php if ($gender=='female') { echo 'checked'; } ?> />
Female</td>
</tr>
<tr>
<td width="10%">Martial Status</td>
<td><input name="martial" type="text" value="<?php echo @$row['4'];?>" ></td>
</tr>
<tr>
<td width="20%">Contact Number</td>
<td><input name="contact" type="text" value="<?php echo @$row['5'];?>"></td>
</tr>
<tr>
<td width="10%">Email Address</td>
<td><input name="email" type="text" value="<?php echo @$row['6'];?>"></td>
</tr>
<tr>
<td width="10%">Location</td>
<td><input name="location" type="text" value="<?php echo @$row['7'];?>" ></td>
</tr>
<tr>
<td width="10%">Treatment Details</td>
<td></td>
</tr>
<tr>
<td width="10%">Doctor Name</td>
<td><input name="drname" type="text" value="<?php echo @$row['8'];?>" ></td>
</tr>
<tr>
<td width="10%">Clinic Name</td>
<td><input name="cname" type="text" value="<?php echo @$row['9'];?>" ></td>
</tr>
<tr>
<td width="10%">Clinic Location & Branch</td>
<td><input name="clocation" type="text" value="<?php echo @$row['10'];?>" ></td>
</tr>
<tr>
<td width="10%">Implants</td>
<td>
<select name="implants" id="implants" value="<?php echo @$row['11'];?>">
<option <?php if ($implants== '1' ) echo 'selected="selected'; ?> value="1">1</option>
<option <?php if ($implants== '2' ) echo 'selected="selected'; ?> value="2">2</option>
<option <?php if ($implants== '3' ) echo 'selected="selected'; ?> value="3">3</option>
</select>
</td>
</tr>
<tr>
<td width="10%">Problem</td>
<td><input name="problem" type="text" value="<?php echo @$row['12'];?>" ></td>
</tr>
<tr>
<td width="10%">Treatment Given</td>
<td><input name="tgiven" type="text" value="<?php echo @$row['13'];?>" ></td>
</tr>
<tr>
<td width="10%">Treatment Date</td>
<td><input name="tdate" type="date" value="<?php echo @$row['14'];?>" ></td>
</tr>
<tr>
<td>multifile
<td>
<input id="fileupload" type="file" multiple="multiple" />
<hr />
<b>Live Preview</b>
<br />
<br />
<div id="dvPreview">
</div>
</td>
</tr>
<tr>
<td width="10%">X-Ray Image</td>
<td><input name="file" type="file" multiple="" ></td>
</tr>
<?php
if(isset($row['image']))
{
?>
<tr>
<td> </td>
<td><img src="uploads/<?php echo $row['image'];?> " height="50" width="50"></td>
</tr>
<?php
}
?>
<tr>
<td> </td>
<td>
<input name="submit" value="Submit" type="submit" class="submit">
<input name="submit" value="Cancel" type="button" class="submit" onClick="window.location='index.php'">
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
</div>
</article></div>
</div>
</div>
</div>
</div>
<footer class="art-footer clearfix">
<div class="art-footer-inner">
<p>Copyright © 2016. All Rights Reserved.</p>
<p class="art-page-footer">
</p>
</div>
</footer>
</div>
</body></html>
<!-------------End of new code------------------->
&#13;
<?php
$files = glob("uploaded/*.*");
for ($i=1; $i<count($files); $i++)
{
$image = $files[$i];
print $image ."<br />";
echo '<img src="'.$image .'" alt="Random image" height="300px" width="300px"/>'."<br /><br />";
}
?>
&#13;