php - CRUD: Update 2 files on server and mySQL record -


i have form built out in can upload 2 files record, , files save server, , information inputted mysql database. files upload , delete now, cannot "update" functionality working. want old files deleted server, new ones uploaded, , information updated in mysql database.

i receive error:

error: `visible` = 'n', `homepage` = 'n', `fa_id` = '', `title` = 'tester', `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

any appreciated. thank you!

<?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 missing or invalid or      // page couldn't found in database     redirect_to("manage_content.php");   } ?> <?php   if (isset($_post['submit'])) {     // process 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 {     // 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: high quality , comprehensive middle school 5th through 8th grade boys low-income communities in 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 variable, doesn't use 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 &lsquo;yes&rsquo; selected, item publicly visible on website 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 &lsquo;yes&rsquo; selected, item featured on <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 sure? can&rsquo;t 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);   } ?> 


Comments