在我的第一个UPDATE语句上,我正在尝试让我的WHERE值包含变量$ couponCode,但到目前为止它不起作用。这样,正确的行将根据输入内容进行更新。任何帮助,将不胜感激。
if ($couponCode == $coupons_db3['coupon_code']){ echo $couponCode; $stmt = $db->prepare('UPDATE promocode_3 SET used = 1 WHERE coupon_code ='.$couponCode); $stmt = $db->prepare('UPDATE usr_customer_profile SET packageid = 3 WHERE usrcustomerid = :usrcustomerid'); $stmt->bindValue(':usrcustomerid', $_SESSION['usrcustomerid'], PDO::PARAM_INT); $stmt->execute(); break; }
您还需要绑定couponCode。
couponCode
if ($couponCode == $coupons_db3['coupon_code']){ echo $couponCode; $stmt = $db->prepare('UPDATE promocode_3 SET used = 1 WHERE coupon_code =:couponCode'); $stmt->bindValue(':couponCode', $couponCode, PDO::PARAM_STR); $stmt->execute(); $stmt = $db->prepare('UPDATE usr_customer_profile SET packageid = 3 WHERE usrcustomerid = :usrcustomerid'); $stmt->bindValue(':usrcustomerid', $_SESSION['usrcustomerid'], PDO::PARAM_INT); $stmt->execute(); break; }