从url更新id

时间:2016-04-15 04:56:29

标签: pdo

目前我正在尝试从网址ID运行更新,我可以检索它ID但是我的更新似乎有些问题,而不是确定我哪里出错了

 require_once'connection.php';



        $getCode = $db->prepare("
                        SELECT username, activecode FROM username WHERE activecode = ?
                    ");
        $getCode->execute( array ( $_GET["activecode"] ) );


$sql = "UPDATE `username` SET `active` = '1'
    WHERE `activecode` = :activecode"; 

//  var_dump($sql);
    $stmt = $db->prepare($sql);
    $stmt->bindParam(':activecode', $getCode);
    $stmt->execute();

1 个答案:

答案 0 :(得分:1)

<?php
   require_once'connection.php';
   $getCode = $db->prepare(" SELECT username, activecode FROM username WHERE activecode = :activecode");
   $getCode->bindParam(':activecode', $_GET["activecode"] );
   $getCode->execute( );


   $sql = "UPDATE username SET active = '1'  WHERE activecode = :activecode"; 
 //  var_dump($sql);
 $stmt = $db->prepare($sql);
 $stmt->bindParam(':activecode',  $_GET["activecode"]);
 $stmt->execute();
?>