I have two table with same column name. I need make search and update in single form for that's two tables.
Here is my code form search and fetch data (looklike working):
if(isset($_POST['Search'])) {
$NoMohon = $mysqli->real_escape_string($_POST['Nomor']);
//query database
$resultSet = $mysqli->query("SELECT * FROM table1 WHERE Nomor = '$Nomor' union SELECT * FROM table2 WHERE Nomor = '$Nomor'");
if($resultSet->num_rows > 0) {
while($rows = $resultSet->fetch_assoc()) {
$Nomor = $rows['Nomor'];
$Name = $rows['Name'];
$Age = $rows['Age'];
}
} else {
$output = "Data Null!";
}
}
and here my code to update table :
if(isset($_POST['Save'])) {
$Nomor = $mysqli->real_escape_string($_POST['Nomor']);
//query database
$resultSet = $mysqli->query("SELECT * FROM table1 WHERE Nomor = '$Nomor' union SELECT * FROM table2 WHERE Nomor = '$Nomor'");
$Name = strtoupper($_POST['Name']);
$Age = strtoupper($_POST['Age']);
//NEED WORKING CODE HERE
$sql = $mysqli->query("UPDATE table1 SET Name ='{$Name}', Age ='{$Age}' where Nomor='$Nomor' union UPDATE table2 SET Name ='{$Name}', Age ='{$Age}' where Nomor='$Nomor'");
header('Location: sukses.php');
}
If search result is value in table2, then i want update value in table2 only. If search result is value in table1, then i want update value in table1 only.
table1
+-------+-------------+---------+
| Nomor | Name | Age |
+-------+-------------+---------+
| a1 | Supar | 25 |
| a2 | Rambo | 23 |
+-------+-------------+---------+
table2
+-------+-------------+---------+
| Nomor | Name | Age |
+-------+-------------+---------+
| b1 | Boneng | 28 |
| b2 | Dennyius | 32 |
+-------+-------------+---------+
Code above for update not working. so please help me here. any help would be appreciated. Thanks