2016-11-11 46 views
-1

我正面臨着未定義的索引問題。我檢查了我的html圖像代碼,看起來不錯。在提交網站中使用undefined常量

,但它仍然顯示問題,當我嘗試更新的頁面

它的主要問題是,當我更新的頁面,

顯示它是這樣的

注意:未定義的索引:圖像中 /Applications/XAMPP/xamppfiles/htdocs/cms/admin/includes/edit_post.php 上線31

說明:Undefin ED指數:圖像中 /Applications/XAMPP/xamppfiles/htdocs/cms/admin/includes/edit_post.php 上線32

QUERY FAILED .You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '= '2', post_title = 'javascript', post_date = now(), post_author = 'Winter', pos' at line 1 

所以,Im相當肯定我對這些查詢一些語法問題行,也許我忘了添加一些行的空間?

我相信函數confirm()很好,它只是一個函數名。

$query ="UPDATE posts SET"; 
     $query .="post_category_id = '{$post_category_id}', "; 
     $query .="post_title = '{$post_title}', "; 
     $query .="post_date = now(), "; 
     $query .="post_author = '{$post_author}', "; 
     $query .="post_status = '{$post_status}', "; 
     $query .="post_tags = '{$post_tags}' , "; 
     $query .="post_content = '{$post_content}', "; 
     $query .="post_image ='{$post_image}' "; 
     $query .="WHERE post_id = {$the_post_id} "; 

     $update_post = mysqli_query($connection,$query); 


     confirm($update_post); 
     //  if(! $update_post) //  die("QUERY FAILED" . mysqli_error($connection)); 

這是圖像格式組HTML代碼

我籤的名字=「post_image」他們似乎比賽。

我檢查了其他人的問題,但仍不明白爲什麼有一個通知在這裏。

$query = "SELECT * FROM posts WHERE post_id = $the_post_id "; 
      $select_posts_by_id = mysqli_query($connection,$query); 

      while($row = mysqli_fetch_assoc($select_posts_by_id)){ 


      $post_image = $row['post_image']; 


      } 

    if(isset($_POST['update_post'])){ 

      $post_image = $_FILES['image']['name']; 
      $post_image_temp = $_FILES['image']['tmp_name']; 


     move_uploaded_file($post_image_temp, "../images/$post_image"); 


} 

<div class="form-group"> 
     <label for="post_image">Post Image</label> 
     <img width="100" src="../images/<?php echo $post_image ?>" alt="" > 
     <input type="file" name="post_image"> 
    </div> 

回答

1

注意:未定義指數:圖像

這意味着比輸入,您可以上傳文件,它的名字是 'post_image'

<input type="file" name="post_image"> 

比你的PHP代碼,你有

$post_image = $_FILES['image']['name']; 
$post_image_temp = $_FILES['image']['tmp_name']; 

,必須改變

$post_image = $_FILES['post_image']['name']; 
$post_image_temp = $_FILES['post_image']['tmp_name']; 
0

此代碼:

$query ="UPDATE posts SET"; 
$query .="post_category_id = '{$post_category_id}', "; 

構建字符串UPDATE posts SETpost_category_id = '...'這是MySQL錯誤的來源。

它可能也容易受到SQL injection(具體取決於$post_category_id來自何處以及在用於構建查詢之前如何處理它)。

我建議你使用prepared statements

$query = "UPDATE posts SET post_category_id=?, post_title=? WHERE post_id=?"; 
$stmt = mysqli_prepare($connection, $query); 
mysqli_stmt_bind_param($stmt, 'isi', $post_category_id, $post_title, $the_post_id); 
$update_post = mysqli_stmt_execute($stmt); 

更多的documentation