Php 正在尝试向用户添加点,但不起作用
因此,我试图找到一种方法,在用户每次单击按钮时向其添加一个点,但我一直无法找到它。现在,这个按钮正在显示,当用户单击它时,什么也没有发生。谢谢你的帮助:)Php 正在尝试向用户添加点,但不起作用,php,Php,因此,我试图找到一种方法,在用户每次单击按钮时向其添加一个点,但我一直无法找到它。现在,这个按钮正在显示,当用户单击它时,什么也没有发生。谢谢你的帮助:) 使用者 用户名 这是一个大概的答案。我不得不对您的表模式(我猜有一个userid列)和数据库API(我编写了一个参数化查询,其中的值作为query方法的参数——您可能需要将其重新编码为API的适当方法,我不知道) 使用者 用户名 您的脚本查找Input::get('points'),但您的HTML中有name=“points\u ad
使用者
用户名
这是一个大概的答案。我不得不对您的表模式(我猜有一个userid
列)和数据库API(我编写了一个参数化查询,其中的值作为query
方法的参数——您可能需要将其重新编码为API的适当方法,我不知道)
使用者
用户名
您的脚本查找Input::get('points')
,但您的HTML中有name=“points\u add”
。它也将points
作为一个数字,但您有value=“points+1”
,这是一个字符串。@Barmar我想说的是,获取当前的点数并添加1,您不需要从数据库中获取当前的点数吗,不是从Input::get
?@Barmar yea这就是我正在尝试做的,但我不确定如何做,因此当我单击submit按钮“不可接受请求资源的适当表示/无法在此服务器上找到”时,会出现此错误你是否修正了我所做的假设,使它们与你的数据库和API正确匹配?此外,我不知道这是否有帮助,但我做了一个函数,在用户登录时添加了20个点,看起来像这样“更新用户设定点=点+20,其中用户名='$user\u用户名';
<table align="center">
<caption><b>Users</b></caption>
<br>
<thead>
<tr>
<th>Username</th>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<th><img src="1.png" align="left"></th>
</tr>
</thead>
<tbody>
<?php
$user = new User();
$get_all = DB::getInstance()->query("SELECT * FROM users ORDER BY points DESC Limit 0 , 20");
foreach($get_all->results() as $r) {
?>
<tr>
<td><?php echo ucfirst($r->username); ?>
<?php echo ucfirst($r->points); if($r->points==140) {
echo $r->username;
}?>
<?php ucfirst($r->rank); if($r->points==140) {
echo $r->rank; } ?>
<?php
$user = new User();
if(Input::exists()) {
if(Token::check(Input::get('token'))) {
$newPoints = Input::get('points') + 1;
try {
$user->update(array(
'points' => $newPoints
));
} catch(Exception $e) {
die($e->getMessage());
}
Session::flash('home', 'Your details have been updated.');
Redirect::to('index.php');
}
}
?>
<form method="post">
<input type="submit" name="points_add" value="Points +1">
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
</form></td>
</tr>
<?php }
?>
</tbody>
</table>
<table align="center">
<caption><b>Users</b></caption>
<br>
<thead>
<tr>
<th>Username</th>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<th><img src="1.png" align="left"></th>
</tr>
</thead>
<tbody>
<?php
$get_all = DB::getInstance()->query("SELECT * FROM users ORDER BY points DESC Limit 0 , 20");
foreach($get_all->results() as $r) {
?>
<tr>
<td><?php echo ucfirst($r->username); ?>
<?php echo ucfirst($r->points); if($r->points==140) {
echo $r->username;
} ?>
<?php if($r->points==140) {
echo ucfirst($r->rank);
} ?>
<?php
$user = new User();
if(Input::exists()) {
if(Token::check(Input::get('userid'))) {
$userid = Input::get('userid');
DB::getInstance()->query("UPDATE users SET points = points + 1 WHERE userid = ?", $userid);
Session::flash('home', 'Your details have been updated.');
Redirect::to('index.php');
}
}
?>
<form method="post">
<input type="submit" name="points" value="submit">
<input type="hidden" name="userid" value="<?php echo $r->userid; ?>">
</form></td>
</tr>
<?php }
?>
</tbody>
</table>