-1

I've got a basic Update query:

$sql = "UPDATE `$row[2]` SET `gebuchtvon` = \"$neugebuchtvon\" WHERE `id` = $row[0]";

The sql works fine, if I paste it into the sql field of phpmyadmin but for some reason it does not work from the PHP file.

I have used nearly the same syntax in another file where it works perfectly.

Furthermore I've read that it might not work because the WHERE statement is not met but this can't be the problem because, as I said, it works if I paste it into the SQL field.

Hope some one can help me, thanks in advance :)

UPDATE

$sql =   "SELECT `id`,`gebuchtvon`,'montag' as tag FROM `montag` WHERE `gebuchtvon` <> \"\" "
        ."UNION ALL SELECT `id`,`gebuchtvon`,'dienstag' as tag FROM `dienstag` WHERE `gebuchtvon` <> \"\" "
        ."UNION ALL SELECT `id`,`gebuchtvon`,'mittwoch' as tag FROM `mittwoch` WHERE `gebuchtvon` <> \"\" "
        ."UNION ALL SELECT `id`,`gebuchtvon`,'donnerstag' as tag FROM `donnerstag` WHERE `gebuchtvon` <> \"\" "
        ."UNION ALL SELECT `id`,`gebuchtvon`,'freitag' as tag FROM `freitag` WHERE `gebuchtvon`<> \"\" ";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($result)){
    if(strpos($row["gebuchtvon"],$datum) > 0){//nur wenn es eine Buchung gibt, die heute wieder anfängt
        echo $row["gebuchtvon"]."<br><br>";
        $gebuchtvon = explode("#",$row["gebuchtvon"]);//alle gebuchten Fahrten gesplittet
        for($i=0;$i<count($gebuchtvon);$i++){//durch alle Buchungen laufen
            if(strpos($gebuchtvon[$i],$datum) >0){//wenn die aktuelle Buchung wieder anfängt => aktualisieren
                $offset = strrpos($gebuchtvon[$i],"/");
                $gebuchtvon[$i] = substr($gebuchtvon[$i],0,$offset);
            }
        }
        $neugebuchtvon = implode("#",$gebuchtvon); //neuen TExt imploden um in DB zu schreiben
        echo $neugebuchtvon."<br><br>";
        $sql = "UPDATE `".$row[2]."` SET `gebuchtvon` = \"".$neugebuchtvon."\" WHERE `id` = ".$row[0];
        echo $sql."<br><br>";
        $ergebnis = mysqli_query($conn,$sql);
        echo $ergebnis."<br><br>";
    }
}

I don't know how much code you need...

Sorry for weird variable names I'm German and jsut took things that describe what those variables are doing

Update 2

It's no duplicate. There is no error thus there is no error I can check for.

Update 3

var_dump($row):

array(6) { [0]=> string(1) "3" ["id"]=> string(1) "3" [1]=> string(29) "1/h/2019-03-11#1/r/2019-03-11" ["gebuchtvon"]=> string(29) "1/h/2019-03-11#1/r/2019-03-11" [2]=> string(7) "freitag" ["tag"]=> string(7) "freitag" }

Update 4

The SQL given is: UPDATE freitag SET gebuchtvon = "1/h#1/r" WHERE id = 3 ; Just an example...

tiko_2302
  • 101
  • 8
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/189847/discussion-on-question-by-tiko-2302-mysql-update-does-not-update-but-does-not-gi). – Cody Gray - on strike Mar 12 '19 at 02:34

1 Answers1

-2

You can try this to catch the error:

try {
    $sql = "UPDATE ".$row[2]." SET gebuchtvon = '".$neugebuchtvon."' WHERE id = ".$row[0];
} catch (Exception $e) {
    print_r($e);
    die;
}