dongmao4486 2016-10-11 17:30
浏览 63

intval($ id)不匹配数据库中的id

My update query is not working with my variable $id BUT does work when I use the literal number 29, for example. I have var_dumped $id and I get INT(29). Has something changed recently because I copied code that has worked in the past.

$id = (ISSET($_GET['id'])) ? intval($_GET['id']):0;//prevents sql inject
var_dump($id);

My query that works is the following:

$sqlUpdate = $db->query("UPDATE sites SET site_name='$site_name',population='$population' WHERE id=29");

This query doesn't work:

$sqlUpdate = $db->query("UPDATE sites SET site_name='$site_name',population='$population' WHERE id=$id");
  • 写回答

1条回答 默认 最新

  • dqwnxdhb88531 2016-10-13 15:28
    关注

    I found my issue/answer. I used <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> within my form because the code to process my form posts resides within the same file. Upon hitting 'UPDATE' I noticed in the address bar that the filename was correct but it dropped the GET variable for a brief moment. At this time, the following code ran again...

    $id = (ISSET($_GET['id'])) ? intval($_GET['id']):0;
    $id = protect($db,$id);
    

    and my variable $id was changed from the correct GET value to 0, thus preventing my code from updating the correct record. I changed my code to the following:

    <form method="post" action=""> 
    

    and everything update perfectly. If anyone cares to explain WHY this happened I would greatly appreciate it.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题