Colin Colin - 1 year ago 104
PHP Question

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();

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 );

Answer Source

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 and 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') bellow line you do the mysql connection. You can set at the first line of file :


to show all errors.