2017-02-09 7 views
1

文字列を入力に挿入すると値の更新に問題があります。私の列 "場所"私は更新するデータ型です:varchar()私のデータベースでは。私は "3"のような数字を挿入することができ、それはデータベース上で更新されます。しかし、 "SS14"のような文字列を挿入するとデータベースが更新されず、エラーが発生します。私は間違っているの?文字列としての更新値

SQL文の文字列値で
<?php 
try { 
    // verify request 
    if($_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest') throw new Exception ('No Xrequest'); 


     require_once('db.php'); 

     $q= 'UPDATE prestashop.ps_product SET location = %s WHERE id_product = %d'; 

     $sql = sprintf($q, $_REQUEST['value'], $_REQUEST['id']); 

     $rs=$ib->exec($sql); 
     if (PEAR::isError($rs)) throw new Exception ("DB Request: ". $rs->getMessage()); 

     die("1"); // exit and return 1 on success 
    } catch (Exception $e) { 
     print $e->getMessage(); 
    } ' 


<td class="test" id="'.$r["product_id"].'"><font size=+2> 

<b>'.$r["product_s_desc"].'</b></font></td> 

     <script> 
    var x; 
    var h = 0; // blur fires multiple times, use h to count and fire once 
    var url = 'up.php'; 

    $(".test").on('click', function(d) { 
     d.stopPropagation(); 
     var x = $(d.target); 
     x.html('<input id="edit" style="width: 40px;" value="'+x.text()+'">'); 
     var this_id = x.context.id; 

     $("#edit").on('blur', function(d) { 
      if (h < 1) { 
       h = h+1; 
       d.stopPropagation(); 

       $(d.target.parentElement).text(d.target.value); 

       $.get(url, {id: this_id, value: d.target.value}) 
        .done(function(d){ if(d == undefined || d != 1) { alert('Something went wrong, check your data and results. '+d);}}) 
        .fail(function(d){ alert('error');}); 
       $(".edit").off('blur'); 
      } 

      return false; 
     }); 
     h = 0; 
    }); 
    </script> 
+0

コードは「コードブロック」の正しい順序ではありませんが、私が使用するコードを表示しています。 – Somepub

答えて

1

%s

周りの単一引用符は、あなたはすべてのデータ値の周りに引用符を置くことができ、この

$q= "UPDATE prestashop.ps_product SET location = '%s' WHERE id_product = %d"; 

NOTEのような引用符で囲まなければなりませんが、彼らはありますテキストデータ型を中心とする執行機関。

+0

私はそれを行いました!しかし、それはまだデータベースで更新されず、エラーを表示します – Somepub

+0

ああ、私は問題を発見した、私はダブルの代わりに単一のqoutesを使用!ありがとうございました – Somepub

関連する問題