douhui2307
2012-05-17 09:43
浏览 35
已采纳

所有列都设置为相同的值

I am totally lost as to what is wrong with my script. The JSON data is coming in correctly and the variables $i and $current are all what they should be at every stage in the forloop.

It seems to keep updating my database with the id, so in the case where id is 11, it will update all columns with the number 11.

Here is my script:

if($mode == 'SAVE_BUYING_ROW')
{   
    $JSON = (array)$JSON ;

    include('pdoconnect.php') ;
    $result = $dbh->prepare("UPDATE parts_trading_instructions
                 SET quantity = ?, supplierRef = ?, currencyRef = ?, 
                             net = ?, vat = ?, shippingNet = ?,
                 shippingVat = ?, direct = ?, ebayItemNumber = ?
                 WHERE id = ?") ;
    $i = 0 ;
    foreach($JSON as $current) {
        $current = (string)$current ;
        if($i == 0)
        {
            $i++ ;
            continue ;
        }

            $result->bindParam($i, $current, PDO::PARAM_STR) ;  
        $i++ ;
    }

$result->execute() ;

}

Can anyone see where I am going wrong?

图片转代码服务由CSDN问答提供 功能建议

我完全迷失了我的脚本有什么问题。 JSON数据正确输入,变量$ i和$ current都是forloop中每个阶段的变量。

它似乎一直用id更新我的数据库, 因此,在id为11的情况下,它将更新所有数字为11的列。

这是我的脚本:

  if  ($ mode =='SAVE_BUYING_ROW')
 {
 $ JSON =(array)$ JSON; 
 
 include('pdoconnect.php'); 
 $ result = $ dbh-> prepare(“UPDATE  parts_trading_instructions 
 SET quantity = ?, supplierRef = ?, currencyRef = ?, 
 net = ?, vat = ?, shippingNet =?,
 shippingVat = ?, direct = ?, ebayItemNumber =?
 WHERE id =?“  ); 
 $ i = 0; 
 foreach($ JSON as $ current){
 $ current =(string)$ current; 
 if($ i == 0)
 {
 $ i ++; \  n继续; 
} 
 
 $ result-> bindParam($ i,$ current,PDO :: PARAM_STR);  
 $ i ++; 
} 
 
 $ result-> execute(); 
 
} 
   
 
 

任何人都可以看到我要去的地方 错了?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doutangguali32556 2012-05-17 09:45
    已采纳

    Use bindValue instead of bindParam. bindParam takes a reference to a variable and only reads its value when executing the query. bindValue takes a value immediately.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题