按钮在表问题中执行PHP脚本
我已经设置了一个脚本,在一个表中显示我的数据库的所有成员,这些成员被称为“挂起点”。在该表中有一个按钮,管理员可以单击该按钮将这些挂起的点发送到表中该行的“点”,并将“挂起的点”重置为0。我已经制作了脚本来发送这些要点,但它似乎没有改变任何东西,即使它确实给出了成功的信息。感谢您的帮助 下面的图片将阐明: 发送points sendpoints.php的代码: 显示表格的代码: 在第一个脚本中,未定义$行 编辑:由于代码已更新,逻辑似乎不正确。您需要从$\u POST中提取用户名,并在更新中使用它按钮在表问题中执行PHP脚本,php,mysql,html-table,Php,Mysql,Html Table,我已经设置了一个脚本,在一个表中显示我的数据库的所有成员,这些成员被称为“挂起点”。在该表中有一个按钮,管理员可以单击该按钮将这些挂起的点发送到表中该行的“点”,并将“挂起的点”重置为0。我已经制作了脚本来发送这些要点,但它似乎没有改变任何东西,即使它确实给出了成功的信息。感谢您的帮助 下面的图片将阐明: 发送points sendpoints.php的代码: 显示表格的代码: 在第一个脚本中,未定义$行 编辑:由于代码已更新,逻辑似乎不正确。您需要从$\u POST中提取用户名,并在更新中使
然而,有两个大问题:你不能处理特殊字符的逃逸,比如。这可能会破坏表单,并打开mysql注入安全漏洞。据我所知,您希望只向特定的人发送按钮点击点,但在您的代码中,您正在做其他事情 注意:我在表单中添加了隐藏变量,以便仅向该特定用户发送点
<?
include ("connect.php");
if (isset($_POST['send'])) {
$username=$_POST'username'];
$result = mysqli_query($conn,"SELECT * FROM members WHERE username='$username' ");
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$pendingpoints = $row['pendingpoints'];
$points = $row['points'];
$newpoints = $points + $pendingpoints;
$q=mysqli_query($conn,"UPDATE members SET points='$newpoints',pendingpoints=0 WHERE
username='$username'");
if($q){
echo "Succesfully changed points for that user";
}
}
?>
显示表格的代码:
如何访问sendpoints.php中的$row?好的,我定义了row,但它仍然没有更改任何内容,也没有给出任何错误更新后的$username=$row['username'];这些变量应该在您选择的查询下。我更改了,但仍然是相同的结果。。。那么OP应该做些什么才能让它发挥作用呢?你只是说它没有定义,我也是;在一个评论中,这就是它。没有足够的信息来说明它应该是什么。我猜$row需要更改为$u POSTTrue。我不会碰这个,因为它只会打开一罐虫子。
<?
include ("connect.php");
$submit = $_POST['submit'];
if ($submit) {
$result = mysqli_query($conn,"SELECT * FROM members WHERE pendingpoints > 0 ");
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
while ($row = mysqli_fetch_assoc($result))
{
$username = $row['username'];
$pendingpoints = $row['pendingpoints'];
$points = $row['points'];
$newpoints = $points + $pendingpoints;
$ip = $row['ip'];
echo "<table border='1'>
<tr>
<td><b>Username:</b></td>
<td><b>Pendingpoints:</b></td>
<td><b>IP:</b></td>
<td><b>Confirm Points:</b></td>
</tr>
<tr>
<form id='1' action='sendpoints.php' method='post'>
<td> $username </td>
<td> $pendingpoints </td>
<td> $ip </td>
<td><input type='submit' class='classname' name='send' value='Send'></form></td>
</tr>
<br> </table>";
}
}
?>
<?
include ("connect.php");
if (isset($_POST['send'])) {
$username=$_POST'username'];
$result = mysqli_query($conn,"SELECT * FROM members WHERE username='$username' ");
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$pendingpoints = $row['pendingpoints'];
$points = $row['points'];
$newpoints = $points + $pendingpoints;
$q=mysqli_query($conn,"UPDATE members SET points='$newpoints',pendingpoints=0 WHERE
username='$username'");
if($q){
echo "Succesfully changed points for that user";
}
}
?>
<?
include ("connect.php");
$submit = $_POST['submit'];
if ($submit) {
$result = mysqli_query($conn,"SELECT * FROM members WHERE pendingpoints > 0 ");
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
while ($row = mysqli_fetch_assoc($result))
{
$username = $row['username'];
$pendingpoints = $row['pendingpoints'];
$points = $row['points'];
$newpoints = $points + $pendingpoints;
$ip = $row['ip'];
echo "<table border='1'>
<tr>
<td><b>Username:</b></td>
<td><b>Pendingpoints:</b></td>
<td><b>IP:</b></td>
<td><b>Confirm Points:</b></td>
</tr>
<tr>
<td> $username </td>
<td> $pendingpoints </td>
<td> $ip </td>
<td><form id='1' action='sendpoints.php' method='post'><input type='submit' class='classname' name='send' value='Send'><input type='hidden' name='username' value='$username'></form></td>
</tr>
<br> </table>";
}
}
?>