douji9518 2018-12-29 18:11
浏览 23

如何更新数据库中的数据[重复]

I am new in PHP. I have to try to make a management system with PHP for learning purpose. there is a payment system which is two options one is "paid" and another is "paid later". Now I want to update from the site and use this code --

if(isset($_POST['pay_update'])){    
$payment  = $_POST['payment'];
$query   = "update doctorapp set payment='$payment' where id='$id'";
$result  = mysqli_query($connect, $query);
if($result){
echo "<script>alert('Update Success...')</script>";
echo "<script>window.open('patient-details.php', '_self')</script>";
}else{
echo "Update Failed...";
}

}

when I use 'id' it shows undefine index, and when I do not use 'id' it's working but change for all id. Now I want to know how I will update data for individual 'id'...?

enter code here
</div>
  • 写回答

1条回答 默认 最新

  • dr9379 2018-12-29 18:47
    关注

    You need to define the $id before your updated query,

    EX :

    $id = 1;
    

    If not, you will get undefined error.

    And as other people said in comments, your query is not safe at all, but as you are in learning phase, I would suggest you to learn with up to date tutorials, for example, for queries, use prepared statements and even better use it with PDO.

    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)