Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

I have the following PHP script to update my DB, however, it doesn't work. The two echo's show in the UI that the variables are filled with the correct values. The query doesn't appear to be executed though. I don't get any errors whatsoever.

<?
    $rapportId = $_GET['variable1'];
    $rapportNaam = $_GET['variable2'];

    echo "rapportId = ". $rapportId;
    echo "<br>rapportNaam = ".$rapportNaam;     

    $mysqli = new mysqli("localhost", "twrwe", "twrewtww", "trwtw");

  $mysqli->query("Update Rapporten Set RapportNaam = $rapportNaam
                  Where RapportId = $rapportId
        ")or die(mysqli_error($db));
  $mysqli->commit();
    if ($mysqli->error) {
       printf("Errormessage: %s\n", $mysqli->error);
    }
  mysqli_free_result();
?>

1 Answer

0 votes
by (12.7k points)

You have to use '' for string data in the query as:

$mysqli->query("Update Rapporten 
Set RapportNaam = '$rapportNaam'
Where RapportId = $rapportId
") ;

Looking for a SQL Tutorial? Join the Intellipaat's SQL Course now to gain more knowledge on SQL. 

Related questions

0 votes
1 answer
asked Dec 22, 2020 in SQL by Appu (6.1k points)
0 votes
3 answers
0 votes
1 answer
asked Jan 3, 2021 in SQL by Appu (6.1k points)
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...