2017-02-24 30 views
1

私は2つの問題があります。私の最初の問題は、私のPHPスクリプトにエラーがあることです。それは基本的に私にこの私のSQLクエリが動作しない+ MariaDBに画像を挿入

Fatal error: Uncaught Error: Cannot pass parameter 2 by reference in /customers/1/d/9/the-scientist.fr/httpd.www/api/addPost.php:30 Stack trace: #0 {main} thrown in /customers/1/d/9/the-scientist.fr/httpd.www/api/addPost.php on line 30 

を与え、私の第二の問題は、私は私がBLOB行の画像挿入のためのPHPMyAdminのと同じことをしたい、MariaDBに一列に画像を挿入しようとしているということです。だから、これは私のPHPスクリプトです:

<?php 
try 
{ 
    $db = new PDO('mysql:host=the-scientist.fr.mysql;dbname=the_scientist_fr_appli_posts;charset=utf8', 'the_scientist_fr_appli_posts', 'arthur2205'); 
} 
catch(Exception $e) 
{ 
    die('Erreur : '.$e->getMessage()); 
} 
// $security = new White\Security; 

$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!"); 
// } 

$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', $img); 
$stmt->bindParam(':fullDesc', $fullDesc); 
$stmt->bindParam(':likes', 0); 

$stmt->execute(); 

    // header("Access-Control-Allow-Origin: *"); 
header("Location: form.php?error=$sql"); 

はまた、これは形式です:

<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="Titre" class="AddPosttitle" name="title"> 
      </label> 
      <label class="item item-input"> 
      <input class="description" type="text" placeholder="Mot Clés" 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="Description" class="full" name="full"></textarea> 
      </label> 
      <div class="padding"> 
       <button class="button button-block button-positive submit-btn" type="submit"> 
       Envoyer 
      </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 
    } 
    ?> 

私は聞いて、あなたはより多くの情報が必要な場合は、この時点で、私の問題は、かなり明確であることを考えますコメントセクション。第一の問題について

+1

を私は、これはオンラインテストの問題であれば知りません。正当なPDO接続をここにデータベースに入れないことを検討してください。 (これが正当な接続の場合) –

+0

2番目の問題について:あなたは何をしたいのか、使用しているコードだけを述べたが、問題の内容は示していない。インサートがうまくいかない、データが期待どおりでないなどですか? – jeroen

+0

@ B.Dionys私がやっていることは分かっていますが、私のサーバーからのみMariaDBサーバーにアクセスできます。 –

答えて

2

:あなたが使用している:

$stmt->bindParam(':likes', 0); 

bindParam()は、パラメータ、変数を期待しています。

あなただけの値をバインドしたい場合は、代わりにbindValue()を使用する必要があります。

$stmt->bindValue(':likes', 0); 
関連する問題