我有一个奇怪的问题,我已经在我建立的几个网站上,但我无法找到问题,它似乎很简单,当用户登录到网站时我更新了列的时间戳& #34; member_login"对NOW()工作得很好,唯一的问题是,它还会更新" member_joined"列与" member_login"完全相同时间戳,但代码中的 NOWHERE 我告诉它更新" member_joined"柱!整个登录脚本非常简单:
的login.php
<?php
session_start();
include('includes/db_connection.php');
include('includes/functions.php');
?>
<?php
if (isset($_POST['submitLogin'])) {
$username = trim(strtolower($_POST['username']));
$password = trim(strtolower($_POST['password']));
if (empty($username) || empty($password)) {
include('includes/header.php');
include('includes/navbar.php');
stderr('Please fill in <b>both</b> login fields.');
include('includes/footer.php');
}
$memberInfo = DB::getInstance()->selectOne(
'
SELECT DISTINCT member_username, member_fees_paid, member_fees_paid_on
FROM `membership`
WHERE `member_username` = :member_username
AND `member_password` = :member_password',
[
'member_username' => $username,
'member_password' => $password
]
);
if (!count($memberInfo)) {
include('includes/header.php');
include('includes/navbar.php');
stderr('Sorry, username <b>and/or</b> password combination not found.');
include('includes/footer.php');
} else {
$_SESSION['member'] = $username;
if ($memberInfo['member_fees_paid'] === 'N') {
$payedOn = new \DateTime($memberInfo['member_fees_paid_on']);
$payedOn->setTime(0, 0, 0);
$monthAgo = new \DateTime('28 days ago');
$monthAgo->setTime(0, 0, 0);
if ($monthAgo > $payedOn) {
try {
DB::getInstance()->execute(
'
UPDATE `membership`
SET `member_fees_paid`= \'N\'
WHERE `member_username` = :member_username
AND `member_password` = :member_password',
[
'member_username' => $username,
'member_password' => $password
]
);
header('Location: my-account.php');
} catch (Exception $e) {
include('includes/header.php');
include('includes/navbar.php');
stderr($e->getMessage());
include('includes/footer.php');
}
}
}
try {
DB::getInstance()->execute(
'
UPDATE `membership`
SET `member_login` = NOW()
WHERE `member_username` = :member_username
AND `member_password` = :member_password',
[
'member_username' => $username,
'member_password' => $password
]
);
header('Location: my-account.php');
} catch (Exception $e) {
include('includes/header.php');
include('includes/navbar.php');
stderr($e->getMessage());
include('includes/footer.php');
}
}
}
?>
<?php
include('includes/header.php');
include('includes/navbar.php');
?>
<div class="panel panel-primary">
<div class="panel-heading">Login to your account.</div>
<div class="panel-body">
<form action="login.php" method="post" class="form-horizontal container-fluid" role="form">
<div class="row form-group">
<div class="col-sm-6 text-right">
<label class="control-label">Username:</label>
</div>
<div class="col-sm-6">
<input type="text" name="username" class="form-control" size="40" required="required"/>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label class="control-label">Password:</label>
</div>
<div class="col-sm-6">
<input type="password" name="password" class="form-control" size="40" required="required"/>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label class="control-label" style="display: inline-block;"> </label>
</div>
<div class="col-sm-6 text-right">
<button type="submit" name="submitLogin" class="btn btn-primary">Login</button>
</div>
</div>
</form>
</div>
<div class="panel-footer">Forgot <b>your password</b>? recover it <a href="recover-password.php">here</a>.</div>
</div>
<?php
include('includes/footer.php');
成功登录后,我们只需更新&#34; member_login&#34;的时间戳。并重定向到&#34; my-account.php&#34;页面,它应该工作,但它不断更新&#34; member_joined&#34; colums与&#34; member_login&#34;相同我无法弄清楚为什么这样做,任何帮助将不胜感激!
答案 0 :(得分:2)
如果您的列member_joined
的类型为timestamp
,您可能需要检查更新CURRENT_TIMESTAMP
是否未被使用 - 您可以在数据库读取器(例如phpMyAdmin)中进行检查, SequalPro,Heidi等。
这会自动将日期戳更新为当前日期/时间。