doq1969 2015-12-30 22:08
浏览 61

问:PostGreSQL如何更有效地在SQL命令中传递POST信息

I have a page that brings up a users information and the fields can be modified and updated through a form. Except I'm having some issues with having my form update the database. When I change the update query by hardcoding it works perfectly fine. Except when I pass the value through POST it doesn't work at all.

   if (isset($_POST['new']))
    {
   $result1 = pg_query($db, 
    "UPDATE supplies.user SET 

        id = '$_POST[id_updated]',  
        name = '$_POST[name_updated]',  
        department = '$_POST[department_updated]',
        email = '$_POST[email_updated]',
        access = '$_POST[access_updated]'    

     where id = '$_POST[id_updated]'");
  if (!$result1)
 {
   echo "Update failed!!";
} else
{
     echo "Update successful;";
}

I did a vardump as an example early to see the values coming through and got the appropriate values but I'm surprised that I get an error that the update fails since technically the values are the same just not being hardcoded..

UPDATE supplies.user SET name = 'Drake Bell', department = 'bobdole',
 email = 'blah@blah.com', access = 'N'  where id = 1 

I also based the form on this link here for guidance since I couldn't find much about PostGres Online Guide

  • 写回答

2条回答 默认 最新

  • dskzap8756 2015-12-30 22:14
    关注

    Try dumping the query after the interpolation should have happened and see what query you're sending to postgres.

    Better yet, use a prepared statement and you don't have to do variable interpolation at all!

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度