doz59484 2014-05-19 19:59
浏览 47
已采纳

PHP问题:删除要在表行GET / POST中回显的按钮

I have a table which selects the results from a database table, with each record there is a Button echoed (DeleteButton). I would like this delete button to delete THE SELECTED ROw (RECORD). My code is presented below, I have narrowed the issue down the 'id' not being POST/GET correctly. I think the form is not passing the id correctly. Can somebody help?

The Form In A Table Cell:

echo "<td>"
.'
<form id="DeleteUser" action="DeleteUser.php" method"post">
<input type"text" name="id" value=" '.$row['user_id'].' " hidden />
<input type="submit" value="Delete">
</form>
'.
"</td>";
echo '</td>';

The Delete Statement (DeleteUser) (DeleteUser.php) :

<?php


$stmt = $con->prepare("DELETE FROM users WHERE user_id = ?");
$stmt->bind_param('sissi',$_GET['id']);
$stmt->execute(); 
$stmt->close();


?>
  • 写回答

1条回答 默认 最新

  • download1214 2014-05-19 20:12
    关注

    Your first parameter on the $stmt->bind_param statement has 5 different parameters. You're only passing one. Change it to this:

    $stmt = $con->prepare("DELETE FROM users WHERE user_id = ?");
    $stmt->bind_param('i',$_GET['id']);
    $stmt->execute(); 
    $stmt->close();
    

    You have to make sure $_GET['id'] is int value also.

    On your <input type"text" name="id" value=" '.$row['user_id'].' " hidden /> line, remove the spaces around value= for the concatenation. So you have value="'.$row['user_id'].'".

    I would also suggest having some kind of check in place to make sure that I can't go in and delete a different user just by inputting a different number in there, random or otherwise.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动