0

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 );
7
  • Take a look into your http servers error log file. That is where you can actually read what the exact issue is instead of having to guess. You cannot develop in php without monitoring that log file. Commented May 15, 2016 at 6:37
  • 1
    I see you quote a field name in your update but that surely would give an error on any system. Commented May 15, 2016 at 6:38
  • 2
    Also note that this code is wide open to sql injection attacks. You really want to fix that. best by stopping to use the old and long deprecated mysql_() functions. Use either the mysqli extension or the PDO package and learn about the benefits of prepared statements and parameter binding. Commented May 15, 2016 at 6:38
  • 1
    Remove those single quotes around olgatermine, your update query should be $sql_befehl_0="UPDATE olgatermine SET ... Commented May 15, 2016 at 6:38
  • The problem is, that i programmed this for a friend, which has now Idea about Servers, and he won't give me the login for the website of the hoster. Commented May 15, 2016 at 6:51

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.