如果用户在MySQL中将字段留空,如何防止int类型将默认值设置为0

时间:2014-07-23 20:29:07

标签: php html mysql

现在我在mysql数据库中有多个字段,我正在从php和HTML脚本中获取输入。我在字段中允许空值,因为并不是所有字段都会被填充。但是当它存储在数据库中时,它被存储为0而不是空值,这不是我想要的。我希望将其存储为空白字段。我后来想从这个领域做出平均值,而0会影响平均值。是否可以停止数据库停止在int类型中将空值设置为0?以下是我用于将数据输入数据库的代码。

error_reporting(E_ERROR | E_PARSE);
$date = $_POST['idate'];
$idate=date("Y-m-d", strtotime($date));
$time = $_POST['timeselect'];
$unitKW = $_POST['kw'];
$unitKv = $_POST['kv'];
$unitwt = $_POST['gwt'];
$unitdsbt = $_POST['dsbt'];
$unitndsbt = $_POST['ndsbt'];
$unitsvo = $_POST['svo'];
$unitdp= $_POST['dp'];
$unitwh = $_POST['whmwc'];
$unitrp = $_POST['rp'];
$unitspeed = $_POST['srpm'];
$server="localhost";
$username="sid";
$password="sid";
$connect_mySql=mysql_connect($server,$username,$password);
$mysql_db=mysql_select_db("kccl",$connect_mySql);
$sql = "INSERT INTO unit_a "."(date,time,KW,KV,winding_temp,ds_bearing_temp,nds_bearing_temp,valve_opening,divertor_pos,water_head,reactive_power,speed_rpm) "."VALUES('$idate','$time','$unitKW','$unitKv','$unitwt','$unitdsbt','$unitndsbt','$unitsvo','$unitdp','$unitwh','$unitrp','$unitspeed')";

0 个答案:

没有答案