所以我这里的php是一个更新的mysql查询,声明如果令牌<10,则返回“some error”。。问题是每次执行代码时它都返回错误。以同样的方式每次即使令牌=11。。我根本不懂完整的代码
//如果未登录,请重定向到登录页
if(!$user->is_logged_in()){ header('Location: login.php'); exit(); }
//定义页面标题
$title = 'Dashboard ~ Pixel Jag.';
//包含页眉模板
require('layout/header.php');
?>
<div class="container">
<div class="panel panel-default">
<?php
$servername = "localhost";
$username = "user";
$password = "pass";
$dbname = "database";
//创建连接
$db = mysqli_connect($servername, $username, $password, $dbname);
//检查连接
if (!$db) {
die("Connection failed: " . mysqli_connect_error());
}
if (($_SESSION['tokens'] < 10)) {
echo "<ul class='list-group'><li class='list-group-item list-group-item-danger'>You do not have enough tokens!</li></ul>";
}
else {
$sql = "UPDATE members SET tokens=tokens - 10, tokenstatus='(Pending Tokens)' ,tokenswith=tokenswith + 10, tokenstatus1='(Pending Tokens)' WHERE username = '".($_SESSION['username']) ."'";
}
if (mysqli_query($db, $sql)) {
echo "<ul class='list-group'><li class='list-group-item list-group-item-success'><h4>Record updated successfully!</h4></li></ul>";
} else {
echo "Error updating record: " . mysqli_error($db);
}
mysqli_close($db);
?>
<div class="panel-footer">
<a href="index.php"><h4>Back To Dashboard..</h4></a>
</div>
</div>
</div>
<?php
//包含页眉模板
require('layout/footer.php');
?>
1条答案
按热度按时间rryofs0p1#
一定是因为session变量中的值小于10。试着检查以下事项1。你开始上课了吗?2如果是,则会话已启动,然后尝试回显会话3的值。如果会话已启动,并且值显示为零,请转到尝试放置会话变量值的位置,并检查是否存在拼写错误或插入错误。