duanchuopi2298 2012-06-21 13:47
浏览 61
已采纳

PHP PDO UPDATE表无法正常工作

I'm using the PHP PDO's to insert and update values in a table. The insertion works fine. But when i try to update, nothing happens. I get no errors, no exceptions.

the code is

   $sql="UPDATE customers SET Name=:name,Company=:company,Address=:address,City=:city,State=:state,Country=:country,MainP=:phonem,CellP=:phonec,Email=:email,Action=:action WHERE CompanyID=:cid";

and the rest:

               $stmt = $dbh->prepare($sql);
                 $stmt->bindParam(":name",$name);
                $stmt->bindParam(":company",$company);
                $stmt->bindParam(":cid",$customer_id);
                $stmt->bindParam(":address",$address);
                $stmt->bindParam(":city",$city);
                $stmt->bindParam(":state",$state);
                $stmt->bindParam(":country",$country);
                $stmt->bindParam(":phonem",$main_num);
                $stmt->bindParam(":phonec",$cell_num);
                $stmt->bindParam(":email",$email);
            $stmt->bindParam(":action",$action);
            $stmt->execute();
           echo $stmt->rowCount();

So, is there something I am doing wrong?

EDIT: Forgot to mention that i am getting a row count of 0. And I've tried without the quotes. It still doesnt work

EDIT: Just found out that customer_id is being returned as 0 froma nother function. Thanks for the help.

  • 写回答

4条回答 默认 最新

  • dr897777 2012-06-21 13:58
    关注

    May be there is no data that query can update ,when using strings like name in query ,try giving like & % to be safe(there may be empty spaces if not taken care off while inseting)

    example

    WHERE Name like '%name%";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)