duansao6776 2015-08-27 07:24
浏览 42

插入的任何数字在mysql中显示为1

When I enter value to db its only inserting a 1 instead of the whole value entered.

$price1=$_POST['proprice'];
$price2=$_POST['proprices'];
if($price2>0){$price=$price2 && $prices=$price1;}else{$price=$price1 && $prices=0;}
$query = "UPDATE products SET pname =:proname,pdesc=:prodesc,pfeat=:profeat,pprice='$price',pprice2='$prices',pcondition='$_POST[pcondition]',pmanu='$_POST[promanu]',plink='$_POST[prolink]'WHERE pid=$post"; 
  • 写回答

2条回答 默认 最新

  • dongzhi2014 2015-08-27 07:30
    关注

    The expression

    $price=$price2 && $prices=$price1;
    

    is evaluated as

    $price=($price2 && ($prices=$price1));
    

    and not as

    ($price=$price2) && ($prices=$price1);
    

    Therefore you yield the result of the boolean expression as value for $price.

    Substitute the && by ;, as in

    if($price2>0){$price=$price2; $prices=$price1;}else{$price=$price1; $prices=0;}
    

    Your &&-interconnected code would also result in not being executed $prices=0; if $price1 is zero.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?