I wanted to ask for help in a mini project, the project consists of updating two records of a MySQL database, I have a record that is called nom and another one that is called code, I want to enter a page html or Php (I do not care, either) and change the registry, for example, if I have a registry with the name Juan and with the code 123456, I want to be able to rename the name and the code, in The table there are only 2 columns the nom and the code.
I hope I explained correctly and thank you very much for the help.
Code1:
<?php
$servername = "localhost";
$username = "***";
$password = "***";
$dbname = "***";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT code, name FROM codes";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table><tr><th>ID</th><th>Name</th></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["code"]."</td>"
"<td>".$row["name"]." </td>"
"<td><a href='editar.php?id=".$row["code"].&.$row["name"]."'>Editar</a></td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
Code2:
$username = "***";
$password = "***";
$dbname = "****";
$nom = $_GET["nom"]
$_GET["code"]
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE nom, code SET WHERE name=$nom";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
?>