store as DECIMAL datatype in MySQL db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
zplits
Forum Contributor
Posts: 158
Joined: Sun Aug 03, 2008 8:59 pm

store as DECIMAL datatype in MySQL db

Post 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?
pawarnilesh4u
Forum Newbie
Posts: 6
Joined: Thu Aug 21, 2008 10:16 am
Location: Mumbai - India

Re: store as DECIMAL datatype in MySQL db

Post 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."');";
User avatar
zplits
Forum Contributor
Posts: 158
Joined: Sun Aug 03, 2008 8:59 pm

Re: store as DECIMAL datatype in MySQL db

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: store as DECIMAL datatype in MySQL db

Post by s.dot »

Show us your insert query.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
zplits
Forum Contributor
Posts: 158
Joined: Sun Aug 03, 2008 8:59 pm

Re: store as DECIMAL datatype in MySQL db

Post 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
Post Reply