gpt4 book ai didi

PHP/SQL - 更新、执行并返回成功但数据库中没有更新

转载 作者:太空宇宙 更新时间:2023-11-03 10:25:04 24 4
gpt4 key购买 nike

我有以下 php/sql 请求:

连接成功,更新成功(返回success msg),但是在phpMyAdmin中,数据库还没有更新。我做错了什么?

<?php 

{ // Connect and Test MySQL and specific DB (return $dbSuccess = T/F)

$hostname = "localhost";
$username = "root";
$password = "";
$databaseName = "db_test";
$dbConnected = mysql_connect($hostname, $username, $password);
$dbSelected = mysql_select_db($databaseName,$dbConnected);

$dbSuccess = true;
if ($dbConnected) {
if (!$dbSelected) {
echo "DB connection FAILED<br /><br />";
$dbSuccess = false;
}
} else {
echo "MySQL connection FAILED<br /><br />";
$dbSuccess = false;
}
}

// Execute code ONLY if connections were successful
if ($dbSuccess) {

// SQL to change country value from UK to United Kingdom
$company_SQLupdate = "UPDATE tCompany SET ";
$company_SQLupdate .= "COUNTRY = 'United Kingdom' ";
$company_SQLupdate .= "WHERE COUNTRY = 'UK' ";
if (mysql_query($company_SQLupdate)) {
echo "UPDATE tCompany.COUNTRY - SUCCESSFUL.<br /><br />";
} else {
echo "UPDATE tCompany.COUNTRY - FAILED.<br /><br />";
}
}

?>

最佳答案

您确定数据库中有包含 country = 'UK' 的记录吗?

您可以更改显示完整查询的成功消息,然后尝试在 phpMyAdmin 中执行该语句并查看修改是否出现。

关于PHP/SQL - 更新、执行并返回成功但数据库中没有更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6924802/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com