php - 为什么我的 PHP/MySQL 是插入而不是更新?

标签 php mysql insert sql-update

if ($Funct == "BUILD" AND $Mode == "GROUND")
{
    $sql = "SELECT * FROM $landCon WHERE North = '" . $North . "' AND West = '" . $West ."'" ;
    $result = mysql_query($sql) or die("Error occurred in [$sql]: " . mysql_error());
    $count = mysql_num_rows($result);

    If ($Count == 0 )
    {
        $sql = "INSERT INTO $landCon (West,North,Type1) VALUES ($West,$North,'$Char')";
        mysql_query($sql) or die("Error occurred in RootA as:[$sql]: " . mysql_error());

    }
    else
    {
        $result=mysql_query("UPDATE $landCon SET Type1= '$Char' WHERE North = $North AND West=$West") or die( "Database Error: ".mysql_error());
    }
    echo "SUCCESS";
}

它不是更新条目存在的位置,而是插入。我的意图是在已经存在指定的 $North$South 条目时更新它,以便每个 map 网格只有一个北/南值。

最佳答案

$count = mysql_num_rows($result);

If ($Count == 0 )

$count $Count 吗?

captcha:当你输入错误时自动初始化新变量的语言

关于php - 为什么我的 PHP/MySQL 是插入而不是更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15422169/

相关文章:

php - 如何将数组参数传递给laravel中的中间件

MySQL Delcare 导致错误

php - 将数据库行放入关联数组的简单方法

javascript - Tampermonkey,Chrome如何自动向表中插入行?

mysql - 复制 MySQL 表并填充其他字段

javascript - 如何在 PHP 中获取 HTML 按钮数据值 ="1"?

php - 使用下拉菜单对电影进行排序

javascript - 当滚动 DIV Tooltip 快速移动时

postgresql - 在多个表中插入动态列列表的函数

mysql - 为什么程序中游标取空?