Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save barmgeat/f445c49ec5d2fc31bf3a66248e085808 to your computer and use it in GitHub Desktop.

Select an option

Save barmgeat/f445c49ec5d2fc31bf3a66248e085808 to your computer and use it in GitHub Desktop.

Revisions

  1. barmgeat created this gist Dec 28, 2020.
    23 changes: 23 additions & 0 deletions Update Data In a MySQL Table Using MySQLi.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    <?php
    $servername = "localhost";
    $username = "username";
    $password = "password";
    $dbname = "myDB";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    }

    $sql = "UPDATE MyGuests SET lastname='Doe' WHERE id=2";

    if ($conn->query($sql) === TRUE) {
    echo "Record updated successfully";
    } else {
    echo "Error updating record: " . $conn->error;
    }

    $conn->close();
    ?>