简体   繁体   中英

PHP mySQL Update doesn't work

I currently have a very big problem with PHP and 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. 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. 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? Because in the newest versions of php the mysql functions are deprecated/removed, use instead mysqli. Try to echo a mysqli_error at the end of the code, also mysql_error if your version of php accepts mysql functions.

If not version of php is the problem check this:

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. You can set at the first line of file:

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

to show all errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM