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";
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.
Learn about operator precedence:
&&
has higher precedence (= is evaluated earlier) than =
, meaning your expression becomes:
$price = (($price2 && $prices) = $price1);
when you &&
two integers, it returns 1
if they are both non-zero. And that value you assign to $price
.