Page 1 of 1

store as DECIMAL datatype in MySQL db

Posted: Thu Aug 21, 2008 10:39 am
by zplits
good day everyone.

I have a problem. I have a mySQL database namely "prices" and a table name of "pricesTbl".
the pricesTBL table consist of 3 fields namely, id, expense, revenue.

id = INT
expense = DECIMAL(10,2)
revenue = DECIMAL(10,2)

I know how to display it in my form's textfield. But when i tried to set new price and edit those fields, it doesn't store the exact amount that i have entered in the form. For example, i entered 3000.00 in expense field, and 5000.00 in the revenue field, the thing that it will store in my database is 3.00 and 5.00...

Does anyone know how to solve this up?

Re: store as DECIMAL datatype in MySQL db

Posted: Thu Aug 21, 2008 10:52 am
by pawarnilesh4u
I dont know whether you are doing this or not but While writing insert query like
insert into tablename (id, expence, revenue) values('1','100.20','12000.00');

if you are taking values from somewhere it must be like this

$sql="insert into tablename (id, expence, revenue) values('1','".$value."','".$value2."');";

Re: store as DECIMAL datatype in MySQL db

Posted: Thu Aug 21, 2008 11:11 am
by zplits
I'm using this code to display it in my page

Code: Select all

    $row=mysql_fetch_array($result);
        $a=$row['deluxeSingle'];
        $b=$row['deluxeDouble'];
        $c=$row['superSingle'];
        $d=$row['superDouble'];     
        $e=$row['junior'];
        $f=$row['executive'];
        $g=$row['senior'];
        $h=$row['imperial'];
        $i=$row['royal'];
        $j=$row['extraPerson'];
        
        $da = "P ".number_format($a, 2, '.', ',');
        $db = "P ".number_format($b, 2, '.', ',');
        $dc = "P ".number_format($c, 2, '.', ',');
        $dd = "P ".number_format($d, 2, '.', ',');
        $de = "P ".number_format($e, 2, '.', ',');
        $df = "P ".number_format($f, 2, '.', ',');
        $dg = "P ".number_format($g, 2, '.', ',');
        $dh = "P ".number_format($h, 2, '.', ',');
        $di = "P ".number_format($i, 2, '.', ',');
        $dj = "P ".number_format($j, 2, '.', ',');
What should i do in order for me to store data in my database just like what i've entered in my form

Re: store as DECIMAL datatype in MySQL db

Posted: Thu Aug 21, 2008 12:20 pm
by s.dot
Show us your insert query.

Re: store as DECIMAL datatype in MySQL db

Posted: Thu Aug 21, 2008 9:16 pm
by zplits
here is the insert query code

Code: Select all

    // Define $myusername and $mypassword
    $a=$_POST['a'];
    $b=$_POST['b'];
    $c=$_POST['c'];
    $d=$_POST['d'];
    $e=$_POST['e'];
    $f=$_POST['f'];
    $g=$_POST['g'];
    $h=$_POST['h'];
    $i=$_POST['i'];
    $j=$_POST['j'];
    
    // update data in mysql database
    $sql="UPDATE $tbl_name SET deluxeSingle = '$a', deluxeDouble = '$b', superSingle='$c', superDouble='$d', junior ='$e', executive = '$f', senior = '$g', imperial = '$h', royal = '$i', extraPerson = '$j'";
    $result=mysql_query($sql);
thank you for your kindness