[英]PHP mySQL Update doesn't work
I currently have a very big problem with PHP and mySQL. 我目前在PHP和mySQL方面有很大的问题。 I moved a System I coded to a new Server.
我将编码的系统移到了新服务器上。 And while everything worked fine on the old Server, I had some problems on the new Server.
尽管在旧服务器上一切正常,但在新服务器上却遇到了一些问题。 Especially with mySQL.
特别是对于mySQL。 While I solved nearly all of them, I have one which I can't seem to get a hold on.
当我解决了几乎所有问题时,我似乎无法坚持下去。 And after 2 hours of trying i searched on the Internet for another two hours and updated my Syntax several times.
经过2个小时的尝试,我又在互联网上搜索了两个小时,并多次更新了我的语法。 But nothing seems to work.
但是似乎没有任何作用。 So now I'm here.
所以现在我在这里。 I get a Connection to the database without a problem, but I can't update the values.
我可以毫无问题地连接到数据库,但是我无法更新值。 I hope you can help me.
我希望你能帮助我。
//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 );
What version of php use? 什么版本的php使用? Because in the newest versions of php the mysql functions are deprecated/removed, use instead mysqli.
因为在最新版本的php中,不赞成使用/删除mysql函数,所以请改用mysqli。 Try to echo a mysqli_error at the end of the code, also mysql_error if your version of php accepts mysql functions.
尝试在代码末尾回显mysqli_error,如果您的php版本接受mysql函数,则也回显mysql_error。
If not version of php is the problem check this: 如果不是php版本的问题,请检查以下内容:
Wrong things what i see in your code..: 我在您的代码中看到的东西是错误的:
$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."';";
You need to run mysql_select_db('dbname')
below line you do the mysql connection. 您需要在执行mysql连接的行下面运行
mysql_select_db('dbname')
。 You can set at the first line of file: 您可以在文件的第一行进行设置:
ini_set('display_errors',1);
error_reporting(E_ALL);
to show all errors. 显示所有错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.