dongyi1524 2014-04-12 17:11
浏览 23

Php mysql更新不会更新

I know mysql is oudated like yahoo. but, I was asked to fix on a friends website. so first of all, heres the code:

<?php
$name = $_POST['name'];
$kcid = $_POST['kcid'];

$host="localhost"; // Host name 
$username="username"; // Mysql username 
$password="password"; // Mysql password 
$db_name="dbname"; // Database name 
$tbl_name="tablename"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// update data in mysql database 
$sql="UPDATE $tbl_name SET lastname='$name' WHERE KcID='$kcid'";
$result=mysql_query($sql);

// if successfully updated. 
if($result){
echo "Successful";
echo "<BR>";
}

else {
echo "ERROR";
}

?>

When i try to run it, it says sucessful but it doesnt edit anything at all talbe:

KcID | Kc | Lastname

I hope somone has a solution.

please correct my code if you see something that causes it not to work

  • 写回答

3条回答 默认 最新

  • duanmiexi2275 2014-04-12 17:20
    关注

    try to type like this:

    $sql="UPDATE {$tbl_name} SET lastname='{$name}' WHERE KcID='{$kcid}'";
    

    without the brackets, it cant understand that '$name' is a php variable.

    评论

报告相同问题?

悬赏问题

  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程