我的table1
和table2
table1
+-------+-------------+---------+
| Nomor | Name | Age |
+-------+-------------+---------+
| a1 | Supar | 25 |
| a2 | Rambo | 23 |
+-------+-------------+---------+
table2
+-------+-------------+---------+
| Nomor | Name | Age |
+-------+-------------+---------+
| b1 | Boneng | 28 |
| b2 | Dennyius | 32 |
+-------+-------------+---------+
我想通过$Nomor
创建搜索表单,以便从两个表格中更新数据$Name
或$Age
。
这里是我搜索n获取数据的代码:
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!";
}
}
这是我更新表的代码:
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: going.php');
}
如果我想将搜索结果b1
名称Boneng
更改为Bonang
或a2
年龄23
更改为{{1},如何使更新代码生效例如。抱歉,如果混淆。 THX