doukang7501 2014-01-06 23:38
浏览 16
已采纳

Php / sql更新仅在cookie是数字时才起作用,而不是在它的文本时

first time posting here.

I'm incredibly new (first day) to using php/mysql. I've managed to write something that displays a value from the database however I'm having a little trouble with allowing the user to edit that value. I've got a form that displays the current value in the database (all varchars) and then allows them to edit it however when i press submit it only actually updates it correctly if the cookie "username" used in the sql contains a number not when it's text...

mysqli_query($con,"UPDATE Customers SET password='".$_POST[password]."' WHERE email=$_COOKIE[username]");

like if cookie[username] contains 123 it will allow me to update other fields relating to it such as "name"/ "address" etc correctly

however if cookie[username] contains any text at all such as "hi" or "food123"it will just stay the same once submit is pressed and I'm not sure why..

Does anyone know what going wrong and why it works for numbers but not for text? Also i wouldn't mind if you could dumb down any help by a considerable amount as i will get lost by any level of complexity... If you need any additional info about my problem just let me know, thanks for any help.

  • 写回答

1条回答 默认 最新

  • dousong2967 2014-01-07 08:08
    关注

    Maybe this help:

    mysqli_query($con,"UPDATE Customers SET password='" . $_POST['password'] . "' WHERE email='" . $_COOKIE['username'] . "'");
    

    I just add single quotes so that the query might read the $_COOKIE[username] as string, So that either number or text would be accepted.

    Keep in mind that using this code, your application may suffer SQL injection.

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

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)