带有日期的数据库字段保持为空
我一直在运行的脚本有问题。
运行查询后,字段 datum_betalen 保持为空。我做错了什么?如果我在执行查询后 echo $datum_betalen ,它就会有一个日期。
//zoek aantal dagen bij betalingstermijn
if($bet_term_maand == 'ja')
{
$aantal_maanden = ceil($bet_term_dagen / 30);
$dagen_resterend = date('t') - date('d') - 1;
$datum_betalen = mktime(0, 0, 0, date('m') + $aantal_maanden , date('d') + $dagen_resterend, date('Y'));
$datum_betalen = date('m-d-Y', $datum_betalen);
}
else
{
$datum_betalen = mktime(0, 0, 0, date('m'), date('d') + $bet_term_dagen, date('Y'));
$datum_betalen = date('m-d-Y', $datum_betalen);
}
// voer query uit
if($land_id == 1)
{
$btw = $config['btw'];
}
else
{
$btw = 0;
}
if($type == 'factuur')
{
$sql = "INSERT INTO 9_factuur_id
(
dossier_id,
factuur_nr,
contact_id,
naam,
btw,
min_orderkosten,
transport,
datum_verstuurd,
bet_term_dagen,
bet_term_maand,
datum_betalen,
soort,
status,
user_id
)
VALUES
(
'".$dossier_id."',
IFNULL((SELECT MAX(factuur_nr) + 1 FROM 9_factuur_id AS temp),'42003'),
'".$contact_id."',
'".$naam."',
'".$btw."',
'".$min_orderkosten."',
'".$transport."',
NOW(),
'".$bet_term_dagen."',
'".$bet_term_maand."',
'".$datum_betalen."',
'factuur',
'open',
'".$_SESSION['user_id']."'
)
";
}
else
{
$sql = "INSERT INTO 9_factuur_id
(
dossier_id,
contact_id,
naam,
btw,
min_orderkosten,
transport,
datum_verstuurd,
bet_term_dagen,
bet_term_maand,
datum_betalen,
soort,
status,
user_id
)
VALUES
(
'".$dossier_id."',
'".$contact_id."',
'".$naam."',
'".$btw."',
'".$min_orderkosten."',
'".$transport."',
NOW(),
'".$bet_term_dagen."',
'".$bet_term_maand."',
'".$datum_betalen."',
'proforma',
'open',
'".$_SESSION['user_id']."'
)
";
}
有什么想法吗?
I have an issue with an script I have been running.
When the query has been run the field datum_betalen stays empty. What have I done wrong? If I echo $datum_betalen after executing the query it has an date.
//zoek aantal dagen bij betalingstermijn
if($bet_term_maand == 'ja')
{
$aantal_maanden = ceil($bet_term_dagen / 30);
$dagen_resterend = date('t') - date('d') - 1;
$datum_betalen = mktime(0, 0, 0, date('m') + $aantal_maanden , date('d') + $dagen_resterend, date('Y'));
$datum_betalen = date('m-d-Y', $datum_betalen);
}
else
{
$datum_betalen = mktime(0, 0, 0, date('m'), date('d') + $bet_term_dagen, date('Y'));
$datum_betalen = date('m-d-Y', $datum_betalen);
}
// voer query uit
if($land_id == 1)
{
$btw = $config['btw'];
}
else
{
$btw = 0;
}
if($type == 'factuur')
{
$sql = "INSERT INTO 9_factuur_id
(
dossier_id,
factuur_nr,
contact_id,
naam,
btw,
min_orderkosten,
transport,
datum_verstuurd,
bet_term_dagen,
bet_term_maand,
datum_betalen,
soort,
status,
user_id
)
VALUES
(
'".$dossier_id."',
IFNULL((SELECT MAX(factuur_nr) + 1 FROM 9_factuur_id AS temp),'42003'),
'".$contact_id."',
'".$naam."',
'".$btw."',
'".$min_orderkosten."',
'".$transport."',
NOW(),
'".$bet_term_dagen."',
'".$bet_term_maand."',
'".$datum_betalen."',
'factuur',
'open',
'".$_SESSION['user_id']."'
)
";
}
else
{
$sql = "INSERT INTO 9_factuur_id
(
dossier_id,
contact_id,
naam,
btw,
min_orderkosten,
transport,
datum_verstuurd,
bet_term_dagen,
bet_term_maand,
datum_betalen,
soort,
status,
user_id
)
VALUES
(
'".$dossier_id."',
'".$contact_id."',
'".$naam."',
'".$btw."',
'".$min_orderkosten."',
'".$transport."',
NOW(),
'".$bet_term_dagen."',
'".$bet_term_maand."',
'".$datum_betalen."',
'proforma',
'open',
'".$_SESSION['user_id']."'
)
";
}
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
datum_betalen
的类型为date
,则应将日期格式更改为Ymd
,因为这是在 MySQL 中使用的。另外我建议避免代码重复;例如:If
datum_betalen
is of typedate
, you should change your date format toY-m-d
as this is used in MySQL. Also I would recommend avoiding code duplication; for example on: