准备好的声明不会工作,正常的sql会

时间:2015-06-23 18:01:08

标签: php sql pdo prepared-statement

我试图将所有未准备好的查询转换为准备好的语句。

在下面的代码中,我已经注释掉了工作中的旧查询,上面是新编写的语句。但是它不适合我。有没有人看到这个有什么问题?

<?php
require_once 'pdocon.php';

if (isset($_POST['card_id'])) {
    $card_id = ($_POST['card_id']);
    $rowname = ($_POST['rowname']);
    $rowothervalue = ($_POST['rowothervalue']);

    $stmt = $conn->prepare("UPDATE cards SET :rowname = :rowothervalue WHERE id= :card_id");

    $stmt->bindParam(':rowname', $rowname);
    $stmt->bindParam(':rowothervalue', $rowothervalue);
    $stmt->bindParam(':card_id', $card_id);

    $stmt->execute();

    // $status_sql='UPDATE cards SET '.$rowname.' = '.$rowothervalue.' WHERE id=' . $card_id . '';
    // $status_result = $conn->query($status_sql);
}

$conn = null;
?>

0 个答案:

没有答案