gpt4 book ai didi

PHP mySQL 更新不起作用

转载 作者:行者123 更新时间:2023-11-29 11:32:05 24 4
gpt4 key购买 nike

我目前在 PHP 和 mySQL 方面遇到了很大的问题。我将我编码的系统移至新服务器。虽然旧服务器上一切正常,但我在新服务器上遇到了一些问题。尤其是 mySQL。虽然我几乎解决了所有问题,但有一个我似乎无法掌握。经过 2 个小时的尝试后,我在互联网上又搜索了两个小时,并多次更新了我的语法。但似乎没有任何作用。所以现在我在这里。我可以毫无问题地连接到数据库,但无法更新值。我希望你能帮助我。

//Connect to mySQL Database
$verbindung = mysql_connect($server, $username, $passwort);
if (!$verbindung) {
echo "Couldn't connect: " . mysql_error();
}
$name=$_POST['fuehrer'];
$ident=$_POST['id'];

//Debugging
echo $name;
echo $ident;

$sql_befehl_0="UPDATE 'olgatermine' SET fuehrer = '".$name."' WHERE ID = '".$ident."';";


if (!mysql_query($verbindung, $sql_befehl_0)){
echo "Couldn't write to database";


}

//Close connection
mysql_close ( $verbindung );

最佳答案

使用什么版本的php?因为在最新版本的 php 中,mysql 函数已被弃用/删除,所以请使用 mysqli。尝试在代码末尾回显 mysqli_error,如果您的 php 版本接受 mysql 函数,也回显 mysql_error。

如果不是 php 版本问题,请检查以下内容:

我在你的代码中看到的错误......:

$sql_befehl_0="UPDATE 'olgatermine' SET fuehrer = '".$name."' WHERE ID = '".$ident."';"; // wrong
should be:
$sql_befehl_0="UPDATE `olgatermine` SET `fuehrer` = '".$name."' WHERE ID = '".$ident."';";

您需要在进行 mysql 连接的行下面运行 mysql_select_db('dbname') 。您可以在文件的第一行设置:

ini_set('display_errors',1);
error_reporting(E_ALL);

显示所有错误。

关于PHP mySQL 更新不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37235279/

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