Update php sql

This article is tagged with: Update php sql and mysql

update php sql

$_old_username = "Randy";
$_new_username = $_POST["username"];
$_sql = "UPDATE user SET first_name = $_new_username WHERE first_name = $_old_username";


The UPDATE statement updates data in a table. It allows you to change the values in one or more columns of a single row or multiple rows.
The following illustrates the basic syntax of the UPDATE statement:
column_name1 = expr1,
column_name2 = expr2,
In this syntax:
First, specify the name of the table that you want to update data after the UPDATE keyword.
Second, specify which column you want to update and the new value in the SET clause. To update values in multiple columns, you use a list of comma-separated assignments by supplying a value in each column’s assignment in the form of a literal value, an expression, or a subquery.
Third, specify which rows to be updated using a condition in the WHERE clause. The WHERE clause is optional. If you omit it, the UPDATE statement will modify all rows in the table.

update table 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;

This article is tagged with: Update php sql and mysql