2017-04-13 5 views
0

내 업데이트 양식으로 두 개의 파일 업로드 필드를 사용할 수 없습니다. create_form을 사용하여 파일을 내 서버에 업로드하고 SQL 데이터베이스에 정보를 입력 할 수는 있지만 오류를받지 않고 편집 할 수는 없습니다. 파일은 업로드되지 않으며 정보는 SQL에서 업데이트되지 않습니다. 도와주세요!두 개의 파일 필드가있는 업데이트 양식

<?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/"; 

$final_image=str_replace(' ','-',$new_image_name); 
$final_file=str_replace(' ','-',$new_file_name); 

    if($_FILES) {   

unlink("images/".$current_event['image']); 
move_uploaded_file($image_loc,$image_folder.$final_image); 

unlink("files/".$current_event['file']); 
move_uploaded_file($file_loc,$file_folder.$final_file); } 

     else 
    { 
    // if no image selected the old image remain as it is. 
    $final_image = $current_event['image']; // old image from database 
    $fine_file = $current_event['file']; // old image from database 

    } 


     $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)) { 

      // Success 
      echo "<pre>".$query."</pre>"; 

      $_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'])) 

?> 

내가 오류는 다음과 같습니다

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'file = '', file_type = '', file_size = '' WHERE events.id = 1 LIMIT 1' at line 1 

답변

0

갱신

$query .= "`image_size` = '{$image_new_size}' "; 

최종 쿼리 그래서

$query .= "`image_size` = '{$image_new_size}' ,"; 

,536,
$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"; 
+0

감사합니다. 이제 텍스트 필드를 수정할 수 있습니다! 그러나 이것은 여전히 ​​이전 파일을 서버에서 삭제하지 않고 새 파일을 업로드하지 않습니다. 어느 쪽도 일어나지 않습니다 ... : – surfingpig

+0

Ok print_r ($ current_event); 데이터 확인 OK –

+0

이미지 유형이 – surfingpig