douiwn6941 2015-02-13 18:50
浏览 166

mysql php UPDATE不起作用

I would like to change data from my mysql database ... but it does't work.

Here is the script:

<?php
session_start();

$con = mysql_connect("localhost", "...", "...");
mysql_select_db('chat',$con);
$uname = $_SESSION['username'];

mysql_query("UPDATE users SET disabled = 'yes' WHERE userame = $uname");

mysql_close($con);

header("Location: logout.php");

?>

How can I update the data? Thanks for your help!

  • 写回答

2条回答 默认 最新

  • doujiao4710 2015-02-13 18:50
    关注

    You forgot to put single quotes around your string value:

    mysql_query("UPDATE users SET disabled = 'yes' WHERE username = '$uname'");
    

    FYI, you shouldn't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

    You may also be open to SQL injections depending on how you obtain the value conained within $_SESSION['username'].

    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作