Search code examples
phpmysqldecimaltextinputmultiplication

how to multiply between decimal and textinput in php?


 $number=$_REQUEST['number'];
 $price=$row2['costpeople'];
 $endprice=$price*$number;

number is the name of input, type of this input is "TEXT" and costpeople is a field of database that type of this field is decimal. when multiply Between price and number and echo $endprice don't show the value of $endprice. This means that don't multiply Between them, please help me. its Necessary for me.


Solution

  • $number = floatval($_REQUEST['number']);
    $price = $row2['costpeople'];
    $endprice=$price*$number;
    

    you can use floatval(), intval() to convert string to number.. source

    You can also do type cast