Here is my code:
DATABASE SETUP
<?php
$user="k*********";
$password="*********";
$database="**********";
mysql_connect("localhost",$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "CREATE TABLE rn (
PID INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(PID),
dait CHAR(10),
rnfl INT ,
)";
mysql_query($query);
mysql_close();
?>
database update
<?php
// Connect to MySQL
mysql_connect("localhost", "*********", "**************") or die(mysql_error());
mysql_select_db("********") or die(mysql_error());
$dait="31/7/2014";
$rnfl=12.9;
// Update
$result = mysql_query("UPDATE rn SET dait='$dait', rnfl='$rnfl' WHERE id=1")
or die(mysql_error());
$result = mysql_query("SELECT * FROM rn WHERE id=1")
or die(mysql_error());
// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array( $result );
echo $row['dait']." - ";
printf('(%5.2d mm)', $row['rnfl']);
?>
THIS IS WHAT I GET AFTER RUNNING THE UPDATE:
31/7/2014 - ( 13 mm)
what I am looking for is: -
31/7/2014 - (12.9 mm)
Well, you're trying to store a float (12.9
) in an INT
type column - integer. Ints do not support decimal places. So basically your question boils down to "I'm bought a banana at the store. Why isn't it an apple?"
Change rnfl
's type to float
or something like decimal(10,2)
if you want to get that .9
back again.
You put the type of rnfl
field as int
- the data will be rounded when you insert them.
Just change the type to float
or, if you're dealing with money, decimal(10,2)
.