2016-11-11 5 views
-1

未定義のインデックスの問題に直面しています。私は自分のhtmlイメージコードをチェックして、うまく見えます。投稿ウェブサイトで定義されていない定数を使用

が、私は、私はページを更新するときに、それの主な問題があるページに

を更新しようとすると、それはまだそれがこの

お知らせのようなものを示して

、問題を示しています。未定義のインデックス: /Applications/XAMPP/xamppfiles/htdocs/cms/admin/includes/edit_post.phpの画像が

31行に関するお知らせ:Undefin ED指数: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 

ので、ライン上の /Applications/XAMPP/xamppfiles/htdocs/cms/admin/includes/edit_post.php の画像、イムかなり確信して私はそれらのクエリにいくつかの構文の問題を抱えていますおそらく、私はいくつかの行にいくつかのスペースを追加することを忘れていますか?

私は関数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' あなたのPHPコードあなたよりも

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

ですhave

$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にもっと読みください。

関連する問題