+ 1
How to update data in mysql using php
How to update data in mysql using php and html form
2 Respostas
+ 2
<?php
$servername = "localhost";
$username = "username"; //change this with your real information
$password = "password"; //change this with your real information
$dbname = "myDB"; //change this with your real information
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//this is just an example of a request
$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();
?>
+ 1
1. Create a html form with GET or POST method and an action that refers to you PHP endpoint.
2. In your PHP endpoint, get the POST or GET values.
3. Establish a mysql connection using PDO, or mysqli.
4. Update your mysql database with previously established connection and obtained POST or GET values.