2017-02-13 5 views
0

私はウェブサイトを作成しており、新しい投稿を追加するフォームがあります。私はIEの完全なサポートのためにajaxの代わりにiFrameを使用しています(わかりました。IEは最も嫌悪感があり、最悪のブラウザの1つですが、いくつかのnoobsがそれを使用しています)。基本的に、私がフォームを提出すると、それは私に内部エラー(500)を与えます。ここで は私のフォームです:PHPでアップロード

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionic/1.3.2/css/ionic.min.css"> 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
<form enctype="multipart/form-data" class="form" id="form" action="./addPost.php" method="POST"> 
     <div class="list"> 
      <label class="item item-input"> 
      <input type="text" placeholder="Title" class="AddPosttitle" name="title"> 
      </label> 
      <label class="item item-input"> 
      <input class="description" type="text" placeholder="Simple Description (max 60 caracters)" maxlength="60" name="description"> 
      </label> 
      <label class="item item-input"> 
      <div> 
       <span id='button_upload'>Image : </span> 
       <input type='file' class="img" name="img"> 
      </div> 
      </label> 
      <label class="item item-input"> 
      <textarea placeholder="Full description" class="full" name="full"></textarea> 
      </label> 
      <div class="padding"> 
       <button class="button button-block button-positive submit-btn" type="submit"> 
       Submit 
      </button> 
      </div> 
     </div> 
    </form> 
    <style type="text/css"> 
     .form { 
      background: #FFF; 

     } 
    </style> 
    <?php 
    if (!empty($_GET['error'])){ 
     ?> 
     <script type="text/javascript"> 
      function findGetParameter(parameterName) { 
       var result = null, 
        tmp = []; 
       var items = location.search.substr(1).split("&"); 
       for (var index = 0; index < items.length; index++) { 
        tmp = items[index].split("="); 
        if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]); 
       } 
       return result; 
      } 
      alert(findGetParameter("error")); 
     </script><?php 
    } 
    ?> 

私はいくつかのコンポーネントを愛するという理由だけで、イオンのライブラリを使用していますが、いずれにせよ、これは私のaddPost.phpファイルです:

<?php 
try 
{ 
    $db = new PDO('mysql:host=something;dbname=someDB;charset=utf8', 'ID', 'LOL'); 
} 
catch(Exception $e) 
{ 
    die('Erreur : '.$e->getMessage()); 
} 

$post = $_POST; 
$img = base64_encode(file_get_contents($_FILES['img']['tmp_name'])); 
$title = addslashes($post['title']); 
$description = addslashes($post['description']); 
$fullDesc = addslashes($post['full']); 
// if (!empty($title) & !empty($description) & !empty($fullDesc) & !empty($img)) { 

// } 
// else { 
// // header("Location: form.php?error=Fill the form!"); 
// } 

$sql = "INSERT INTO posts (title, description, img, fullDesc, likes) VALUES ('$title', '$description', hextoraw('$img')', '$fullDesc', 0)"; 
$db->exec($sql); 
    // header("Access-Control-Allow-Origin: *"); 
header("Location: form.php?error=$sql"); 

私はなぜ知りませんエラーがあります。私はそれがイメージから来ていると思うが、わからない。私はまだ最終的な解決のために努力していますが、私が何かを見つけたら私の質問を編集します(あなたに知らせてください)

+0

ポストへの挿入には余分な引用があります。ちょうどあなたに知らせるために。 – Nello

+1

'hextoraw'が何であっても、文字列を使って関数を呼び出すことはできません。 –

答えて

0
あなたは本当にセキュリティのため prepared statementsを使用する必要があります

$stmt = $db->prepare("INSERT INTO posts (title, description, img, fullDesc, likes) VALUES (:title, :description, :img, :fullDesc, :likes)"); 

$stmt->bindParam(':title', $title); 
$stmt->bindParam(':description', $description); 
$stmt->bindParam(':img', hextoraw($img)); 
$stmt->bindParam(':fullDesc', $fullDesc); 
$stmt->bindParam(':likes', 0); 

$stmt->execute(); 

これは、簡単に再利用可能なステートメントを作成することによっても役立ちます(リンクを参照)。

+0

まあ、予期せぬ問題があります。これは私に次のようなものです: '致命的なエラー:未知のエラー:/api/addPost.php:30の参照によってパラメータ2を渡すことができません。 php on the line 30' '$ stmt-> bindParam( ':likes'、0);' –

0

表示された500のエラーが一般的なエラーページ(スタックトレースまたは詳細エラーメッセージなし)、あなたのWebサーバーのエラーログファイルの最後の行を探して、ここに投稿してください。あなたが持っているエラーについてさらに詳しい情報が必要です。たぶんファイルアクセスエラーですか?データベースエラー ?

また、HEXTORAW Oracle関数を使用して16進文字列をバイナリデータに変換する場合、HEXTORAWはbase 64でエンコードされた文字列ではなく、hexstringで動作することに注意する必要があります。 base64_encodeの代わりに​​を使用してください。

0

あなたは、SQL文字列の誤植があります。 HEXTORAW( '$のIMG')"

削除し、最後の引用符を

関連する問題