我在promotions.php 上有一张图片。当我点击“编辑”链接时,“标题”、“描述”和“图像”等变量将被传递到 doEditPromotion.php 的页面表单。
我可以传递“标题”和“描述”以显示在 doEditPromotion.php 的页面表单上,但不能传递图像值。
谁能帮我这个?谢谢!
doEditPromotion.php -->
<?php
session_start();
include "dbfunction.php";
$id = $_REQUEST['id'];
$query = "SELECT title, description, image, promotionID FROM promotion WHERE promotionID = '$id'";
$result = mysqli_query($link, $query);
$row = mysqli_fetch_array($result);
$title = $row['title'];
$description = $row['description'];
$image = $row['image'];
// check if the form has been submitted. If it has, process the form and save it to the database
if (isset($_POST['save']))
{
$title_save = $_POST['title'];
$description_save = $_POST['description'];
$target = 'images/';
$target = $target.basename($_FILES['photo']['name']);
$pic = ($_FILES['photo']['name']);
move_uploaded_file($_FILES['photo']['tmp_name'], $target);
// check that firstname/lastname fields are both filled in
if ($title_save == '' || $description_save == '' || $pic == '')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';
echo $error;
}
else
{
// save the data to the database
$query = "UPDATE promotion SET title = '$title_save', description = '$description_save', image = '$pic' WHERE promotionID = '$id'";
$result = mysqli_query($link, $query);
// once saved, redirect back to the view page
header("Location: promotions.php");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="codes.css"/>
<link href="styles.css" rel="stylesheet" type="text/css" media="screen" />
<link rel="stylesheet" href="picture-zoom/css/dg-picture-zoom.css" type="text/css" />
<script type="text/javascript" src="picture-zoom/js/external/mootools-1.2.4-core-yc.js"></script>
<script type="text/javascript" src="picture-zoom/js/external/mootools-more.js"></script>
<script type="text/javascript" src="picture-zoom/js/dg-picture-zoom.js"></script>
<script type="text/javascript" src="picture-zoom/js/dg-picture-zoom-autoload.js"></script>
<script>
function myFunction()
{
alert("Are you sure you want to proceed?");
}
</script>
<title>Eco Canteen - Promotions</title>
</head>
<body>
<div id="wrap">
<div id="header">
<div id="logo">
<br/>
<?php
if(isset($_SESSION['username']))
{
?>
<p align="right"><a href="logout.php"><font color="white">Logout</font></a></p>
<?php
}
else
{
?>
<form align="right" name="form" action="doIndex.php" method="post">
<p><label for="username"><font color="white"> Username: </font></label>
<input name="username" type="text"></input>
<label for="password"><font color="white"> Password: </font></label>
<input name="password" type="password"></input>
<input name="submit" value="Login" type="submit"/></p>
<?php
}
?>
</form>
</div>
<div id='menu'>
<ul>
<li><a href='index.php'><span>Home</span></a></li>
<li><a href='promotions.php'><span>Promotions</span></a></li>
<li><a href='outlets.php'><span>Outlets</span></a></li>
<li><a href='feedback.php'><span>Feedback</span></a></li>
<li class='has-sub '><a href='#'><span>Career</span></a>
<ul>
<li><a href='stall.php'><span>Stall Leasing</span></a></li>
<li><a href='career.php'><span>Career Opportunity</span></a></li>
</ul>
</li>
<li><a href='contactUs.php'><span>Contact Us</span></a></li>
</ul>
</div>
</div>
<br/>
<br/>
<p class="slogan"></p>
<div id="intro">
<h2><b>ECO CANTEEN</b></h2>
</div>
<br/>
<div class="wid_center">
<div id="content">
<div class="gao">
<h3><a href="promotions.php">Promotion</a> > <b>Edit Promotion</b></h3>
<fieldset stype='width:500px'>
<legend><b>Promotion Details</b></legend>
<form method="post" enctype="multipart/form-data">
<table>
<tr>
<td>Promotion Title:</td>
<td><input type="text" name="title" size='36' value="<?php echo $title;?>"/></td>
</tr>
<tr>
<td>Description:</td>
<td><input type="text" name="description" style='width: 300px;height:80px' value="<?php echo $description;?>"/></td>
</tr>
<tr>
<td>Image:</td>
<td><input type='file' name='upfile' id='image' src='images/<?php echo $_REQUEST['$image']?>'></input></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="save" value="Save"/></td>
</tr>
</table>
</form>
</fieldset>
</div>
<br/>
<br/>
<hr class="clear" />
</div>
</div>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<div id="footer">
<p> <br />
Copyright © 2012 EcoCanteen<br />
</p></div>
</div>
</body>
</html>