我有一个内置的表单,你可以用你的记录上传两个文件,文件将保存到服务器,信息将输入到mySQL数据库。文件现在上传和删除成功,但我无法获得"更新"功能工作。我希望从服务器删除旧文件,上传新文件,并在mySQL数据库中更新信息。
我目前收到此错误:
错误:`visible` =' N',`homepage` =' N',`fa_id` ='',`title` =&# 39;测试者',`caption` ='',`url` ='',`month` ='',`date` = '',`year` ='',`summary` ='',`full_text` ='',`image `=' 51837 - ',`image_type` ='',`image_size` =' 0' `file` =' 34076 - ',`file_type` ='',`file_size` =' 0'在哪里`events` .id` = 44 LIMIT 1
非常感谢任何帮助。谢谢!
<?php require_once($_SERVER['DOCUMENT_ROOT']."/includes/session.php");?>
<?php require_once($_SERVER['DOCUMENT_ROOT']."/includes/db_connection.php");?>
<?php
session_start();
if($_SESSION["login_user"] != true) {
echo("Access denied!");
exit();
}
?>
<?php require_once($_SERVER['DOCUMENT_ROOT']."/includes/functions.php");?>
<?php require_once($_SERVER['DOCUMENT_ROOT']."/includes/validation_functions.php");?>
<?php find_selected_event_page(); ?>
<?php
if (!$current_event) {
// page ID was missing or invalid or
// page couldn't be found in database
redirect_to("manage_content.php");
}
?>
<?php
if (isset($_POST['submit'])) {
// Process the form
// validations
$required_fields = array("visible");
validate_presences($required_fields);
if (empty($errors)) {
// Perform Update
$id = $current_event["id"];
$visible = mysql_prep($_POST["visible"]);
$homepage = mysql_prep($_POST["homepage"]);
$fa_id = mysql_prep($_POST["fa_id"]);
$title = mysql_prep($_POST["title"]);
$caption = mysql_prep($_POST["caption"]);
$url = mysql_prep($_POST["url"]);
$month = mysql_prep($_POST["month"]);
$date = mysql_prep($_POST["date"]);
$year = mysql_prep($_POST["year"]);
$summary = mysql_prep($_POST["summary"]);
$full_text = mysql_prep($_POST["full_text"]);
$image = rand(1000,100000)."-".$_FILES['image']['name'];
$image_loc = $_FILES['image']['tmp_name'];
$image_size = $_FILES['image']['size'];
$image_type = $_FILES['image']['type'];
$image_folder="images/";
$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$file_folder="files/";
$image_new_size = $image_size/1024;
$file_new_size = $file_size/1024;
$new_image_name = strtolower($image);
$new_file_name = strtolower($file);
$final_image=str_replace(' ','-',$new_image_name);
$final_file=str_replace(' ','-',$new_file_name);
if(file_exists("files/".$current_event['file']))
{
unlink("files/".$current_event['file']);
}
if(file_exists("images/".$current_event['image']))
{
unlink("images/".$current_event['image']);
}
if(move_uploaded_file($image_loc,$image_folder.$final_image))
if(move_uploaded_file($file_loc,$file_folder.$final_file))
$query = "UPDATE `events` SET ";
$query .= "`visible` = '{$visible}', ";
$query .= "`homepage` = '{$homepage}', ";
$query .= "`fa_id` = '{$fa_id}', ";
$query .= "`title` = '{$title}', ";
$query .= "`caption` = '{$caption}', ";
$query .= "`url` = '{$url}', ";
$query .= "`month` = '{$month}', ";
$query .= "`date` = '{$date}', ";
$query .= "`year` = '{$year}', ";
$query .= "`summary` = '{$summary}', ";
$query .= "`full_text` = '{$full_text}', ";
$query .= "`image` = '{$final_image}', ";
$query .= "`image_type` = '{$image_type}', ";
$query .= "`image_size` = '{$image_new_size}' ";
$query .= "`file` = '{$final_file}', ";
$query .= "`file_type` = '{$file_type}', ";
$query .= "`file_size` = '{$file_new_size}' ";
$query .= "WHERE `events`.`id` = {$id} ";
$query .= "LIMIT 1";
$result = mysqli_query($connection, $query);
if ($result && mysqli_affected_rows($connection) >= 0) {
// Success
$_SESSION["message"] = "Item updated.";
redirect_to("manage_content.php");
} else {
// Failure
//$_SESSION["message"] = "Item creation failed.";
//redirect_to("new_news.php");
echo "Error: " . $query . "<br>" . $result->error;
}
}
} else {
// This is probably a GET request
} // end: if (isset($_POST['submit']))
?>
<?php require_once($_SERVER['DOCUMENT_ROOT']."/includes/functions.php");?>
<?php find_selected_event_page(); ?>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Washington Jesuit Adacemy: A high quality and comprehensive middle school for 5th through 8th grade boys from low-income communities in the DC metro area.">
<meta name="keywords" content="">
<meta name="author" content="Washington Jesuit Academy">
<title>Washington Jesuit Academy: About</title>
<link rel="stylesheet" type="text/css" href="https://cloud.typography.com/6113114/6497572/css/fonts.css"/>
<link rel="stylesheet" type="text/css" href="https://cloud.typography.com/683054/7063952/css/fonts.css"/>
<link href="/assets/css/wja.css" rel="stylesheet" type="text/css">
<link href="/assets/css/wja-startup.css" rel="stylesheet">
</head>
<body>
<?php include($_SERVER['DOCUMENT_ROOT']."/includes/navigation.php");?>
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector: 'textarea',
theme: 'modern',
plugins: [
'advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker',
'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking',
'save table contextmenu directionality template paste textcolor'
],
content_css: 'css/content.css',
menubar: 'edit view format',
style_formats: [
{title: 'Blocks', items: [
{title: 'Paragraph', format: 'p'},
]},
{title: 'Headers', items: [
{title: 'Header 1', format: 'h1'},
{title: 'Header 2', format: 'h2'},
{title: 'Header 3', format: 'h3'},
{title: 'Header 4', format: 'h4'},
{title: 'Header 5', format: 'h5'},
{title: 'Header 6', format: 'h6'}
]},
{title: 'Alignment', items: [
{title: 'Left', icon: 'alignleft', format: 'alignleft'},
{title: 'Center', icon: 'aligncenter', format: 'aligncenter'},
{title: 'Right', icon: 'alignright', format: 'alignright'},
{title: 'Justify', icon: 'alignjustify', format: 'alignjustify'}
]}
],
toolbar: 'removeformat | bold italic | bullist numlist outdent indent | link anchor | nonbreaking charmap hr | print preview fullpage | code'
});
</script>
<div class="content">
<div class="block">
<div class="container">
<div class="col=md-12">
<?php // $message is just a variable, doesn't use the SESSION
if (!empty($message)) {
echo "<div class=\"message\">" . htmlentities($message) . "</div>";
}
?>
<?php echo form_errors($errors); ?>
<h2>Edit item</h2>
<form action="edit_event.php?event=<?php echo urlencode($current_event["id"]); ?>" method="post" class="form-horizontal">
<div class="form-group">
<label for="visible" class="col-sm-2 control-label">Published</label>
<div class="col-sm-10">
<label class="radio-inline">
<input type="radio" name="visible" id="visible1" value="N" <?php if ($current_event["visible"] == "N") { echo "checked"; } ?>>
No </label>
<label class="radio-inline">
<input type="radio" name="visible" id="visible2" value="Y" <?php if ($current_event["visible"] == "Y") { echo "checked"; } ?>>
Yes </label>
<p class="small">If ‘Yes’ is selected, the item will be publicly visible on the website as soon as it is saved.</p>
</div>
</div>
<div class="form-group">
<label for="homepage" class="col-sm-2 control-label">Featured on Homepage</label>
<div class="col-sm-10">
<label class="radio-inline">
<input type="radio" name="homepage" id="homepage1" value="N" <?php if ($current_event["homepage"] == "N") { echo "checked"; } ?>>
No </label>
<label class="radio-inline">
<input type="radio" name="homepage" id="homepage2" value="Y" <?php if ($current_event["homepage"] == "Y") { echo "checked"; } ?>>
Yes </label>
<p class="small">If ‘Yes’ is selected, the item will also be featured on the <strong>homepage</strong>.</p>
</div>
</div>
<div class="form-group">
<label for="fa_id" class="col-sm-2 control-label">Form Assembly ID</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="fa_id" value="<?php echo htmlentities($current_event["fa_id"]); ?>" />
</div>
</div>
<div class="form-group">
<label for="month" class="col-sm-2 control-label">Month</label>
<div class="col-sm-10">
<select class="form-control" name="month" value="">
<option value="">Select Month</option>
<option value="01" <?php if ($current_event["month"] == "January") { echo "selected"; } ?>>January</option>
<option value="02" <?php if ($current_event["month"] == "February") { echo "selected"; } ?>>February</option>
<option value="02" <?php if ($current_event["month"] == "March") { echo "selected"; } ?>>March</option>
<option value="04" <?php if ($current_event["month"] == "April") { echo "selected"; } ?>>April</option>
<option value="05" <?php if ($current_event["month"] == "May") { echo "selected"; } ?>>May</option>
<option value="06" <?php if ($current_event["month"] == "June") { echo "selected"; } ?>>June</option>
<option value="07" <?php if ($current_event["month"] == "July") { echo "selected"; } ?>>July</option>
<option value="08" <?php if ($current_event["month"] == "August") { echo "selected"; } ?>>August</option>
<option value="09" <?php if ($current_event["month"] == "September") { echo "selected"; } ?>>September</option>
<option value="10" <?php if ($current_event["month"] == "October") { echo "selected"; } ?>>October</option>
<option value="11" <?php if ($current_event["month"] == "November") { echo "selected"; } ?>>November</option>
<option value="12" <?php if ($current_event["month"] == "December") { echo "selected"; } ?>>December</option>
</select>
</div>
</div>
<div class="form-group">
<label for="month" class="col-sm-2 control-label">Date</label>
<div class="col-sm-10">
<select class="form-control" name="month" value="">
<option value="">Select date</option>
<option value="1" <?php if ($current_event["date"] == "1") { echo "selected"; } ?>>1</option>
<option value="2" <?php if ($current_event["date"] == "2") { echo "selected"; } ?>>2</option>
<option value="3" <?php if ($current_event["date"] == "3") { echo "selected"; } ?>>3</option>
<option value="4" <?php if ($current_event["date"] == "4") { echo "selected"; } ?>>4</option>
<option value="5" <?php if ($current_event["date"] == "5") { echo "selected"; } ?>>5</option>
<option value="6" <?php if ($current_event["date"] == "6") { echo "selected"; } ?>>6</option>
<option value="7" <?php if ($current_event["date"] == "7") { echo "selected"; } ?>>7</option>
<option value="8" <?php if ($current_event["date"] == "8") { echo "selected"; } ?>>8</option>
<option value="9" <?php if ($current_event["date"] == "9") { echo "selected"; } ?>>9</option>
<option value="10" <?php if ($current_event["date"] == "10") { echo "selected"; } ?>>10</option>
<option value="11" <?php if ($current_event["date"] == "11") { echo "selected"; } ?>>11</option>
<option value="12" <?php if ($current_event["date"] == "12") { echo "selected"; } ?>>12</option>
<option value="13" <?php if ($current_event["date"] == "13") { echo "selected"; } ?>>13</option>
<option value="14" <?php if ($current_event["date"] == "14") { echo "selected"; } ?>>14</option>
<option value="15" <?php if ($current_event["date"] == "15") { echo "selected"; } ?>>15</option>
<option value="16" <?php if ($current_event["date"] == "16") { echo "selected"; } ?>>16</option>
<option value="17" <?php if ($current_event["date"] == "17") { echo "selected"; } ?>>17</option>
<option value="18" <?php if ($current_event["date"] == "18") { echo "selected"; } ?>>18</option>
<option value="19" <?php if ($current_event["date"] == "19") { echo "selected"; } ?>>19</option>
<option value="20" <?php if ($current_event["date"] == "20") { echo "selected"; } ?>>20</option>
<option value="21" <?php if ($current_event["date"] == "21") { echo "selected"; } ?>>21</option>
<option value="22" <?php if ($current_event["date"] == "22") { echo "selected"; } ?>>22</option>
<option value="23" <?php if ($current_event["date"] == "23") { echo "selected"; } ?>>23</option>
<option value="24" <?php if ($current_event["date"] == "24") { echo "selected"; } ?>>24</option>
<option value="25" <?php if ($current_event["date"] == "25") { echo "selected"; } ?>>25</option>
<option value="26" <?php if ($current_event["date"] == "26") { echo "selected"; } ?>>26</option>
<option value="27" <?php if ($current_event["date"] == "27") { echo "selected"; } ?>>27</option>
<option value="28" <?php if ($current_event["date"] == "28") { echo "selected"; } ?>>28</option>
<option value="29" <?php if ($current_event["date"] == "29") { echo "selected"; } ?>>29</option>
<option value="30" <?php if ($current_event["date"] == "30") { echo "selected"; } ?>>30</option>
<option value="31" <?php if ($current_event["date"] == "31") { echo "selected"; } ?>>31</option>
</select>
</div>
</div>
<div class="form-group">
<label for="year" class="col-sm-2 control-label">Year</label>
<div class="col-sm-10">
<select class="form-control" name="year" value="<?php echo htmlentities($current_event["year"]); ?>">
<option value="">Select Year</option>
<option value="2000" <?php if ($current_event["year"] == "2000") { echo "selected"; } ?>>2000</option>
<option value="2001" <?php if ($current_event["year"] == "2001") { echo "selected"; } ?>>2001</option>
<option value="2002" <?php if ($current_event["year"] == "2002") { echo "selected"; } ?>>2002</option>
<option value="2003" <?php if ($current_event["year"] == "2003") { echo "selected"; } ?>>2003</option>
<option value="2004" <?php if ($current_event["year"] == "2004") { echo "selected"; } ?>>2004</option>
<option value="2005" <?php if ($current_event["year"] == "2005") { echo "selected"; } ?>>2005</option>
<option value="2006" <?php if ($current_event["year"] == "2006") { echo "selected"; } ?>>2006</option>
<option value="2007" <?php if ($current_event["year"] == "2007") { echo "selected"; } ?>>2007</option>
<option value="2008" <?php if ($current_event["year"] == "2008") { echo "selected"; } ?>>2008</option>
<option value="2009" <?php if ($current_event["year"] == "2009") { echo "selected"; } ?>>2009</option>
<option value="2010" <?php if ($current_event["year"] == "2010") { echo "selected"; } ?>>2010</option>
<option value="2011" <?php if ($current_event["year"] == "2011") { echo "selected"; } ?>>2011</option>
<option value="2012" <?php if ($current_event["year"] == "2012") { echo "selected"; } ?>>2012</option>
<option value="2013" <?php if ($current_event["year"] == "2013") { echo "selected"; } ?>>2013</option>
<option value="2014" <?php if ($current_event["year"] == "2014") { echo "selected"; } ?>>2014</option>
<option value="2015" <?php if ($current_event["year"] == "2015") { echo "selected"; } ?>>2015</option>
<option value="2016" <?php if ($current_event["year"] == "2016") { echo "selected"; } ?>>2016</option>
<option value="2017" <?php if ($current_event["year"] == "2017") { echo "selected"; } ?>>2017</option>
<option value="2018" <?php if ($current_event["year"] == "2018") { echo "selected"; } ?>>2018</option>
<option value="2019" <?php if ($current_event["year"] == "2019") { echo "selected"; } ?>>2019</option>
<option value="2020" <?php if ($current_event["year"] == "2020") { echo "selected"; } ?>>2020</option>
</select>
</div>
</div>
<div class="form-group">
<label for="title" class="col-sm-2 control-label">Title</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="title" value="<?php echo htmlentities($current_event["title"]); ?>" />
</div>
</div>
<div class="form-group">
<label for="author" class="col-sm-2 control-label">Caption</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="caption" value="<?php echo htmlentities($current_event["caption"]); ?>" />
</div>
</div>
<div class="form-group">
<label for="url" class="col-sm-2 control-label">External URL</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="url" value="<?php echo htmlentities($current_event["url"]); ?>" />
</div>
</div>
<div class="form-group">
<label for="summary" class="col-sm-2 control-label">Summary</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="summary" value="<?php echo htmlentities($current_event["summary"]); ?>" />
</div>
</div>
<div class="form-group margin-t-25">
<label for="full_text" class="col-sm-2 control-label">Full Text</label>
<div class="col-sm-10">
<textarea name="full_text" rows="10" style="width:100%"><?php echo htmlentities($current_event["full_text"]); ?></textarea>
</div>
</div>
<div class="form-group"><hr />
<label for="full_text" class="col-sm-2 control-label">Image Upload</label>
<div class="col-sm-10">
<input type="file" name="image" class="mt-3"/> <?php if ($current_event["image"] != NULL) : ; ?>
<?php echo $current_event['file']; ?><?php endif ?>
</div> </div>
<div class="form-group"><hr />
<label for="full_text" class="col-sm-2 control-label">File Upload</label>
<div class="col-sm-10">
<input type="file" name="file" class="mt-3"/> <?php if ($current_event["file"] != NULL) : ; ?>
<?php echo $current_event['file']; ?><?php endif ?>
</div> </div>
<div class="text-right">
<input type="submit" name="submit" class="btn btn-primary m-t-md m-r" value="Save changes" />
<a href="manage_content.php" class="btn btn-default m-t-md">Cancel</a><br>
<a href="delete_event.php?event=<?php echo urlencode($current_event["id"]); ?>" onClick="return confirm('Are you sure? This can’t be undone.');" class="btn btn-danger m-t-md">Delete item</a></div>
</form>
</div>
</div>
</div>
<?php include($_SERVER['DOCUMENT_ROOT']."/includes/footer.php");?>
<!-- JavaScript -->
<script src="../assets/js/jquery.min.js"></script>
<script src="../assets/js/toolkit.js"></script>
<script src="../assets/js/application.js"></script>
</div>
</body></html><?php
// Close database connection
if (isset($connection)) {
mysqli_close($connection);
}
?>