我已经尝试了以下脚本的几种变体,并没有提出一个有效的解决方案。我基本上尝试使用try / catch来运行不同的MySQLi查询。执行时我没有收到任何错误,但我的数据库中没有插入或更新。
$monitor_insert = "INSERT INTO monitors (serial,room,deployed,asset) VALUES ('$monitor','5','$timestamp','$asset')" or die("Error " . mysqli_error($conn));
if (!mysqli_query($conn, $monitor_insert)) {
$monitor_update = "UPDATE monitors SET serial = '$monitor', room = '5', deployed = '$timestamp', asset = '$asset')" or die("Error " . mysqli_error($conn));
if (!mysqli_query($conn, $monitor_update)) {
echo "<p>Nothing Worked!!!</p>";
}
else {
$audit_update = "INSERT INTO audit (code,info) VALUES ('15',Monitor $monitor has been updated to deployed by $uid')";
mysqli_query($conn, $audit_update);
}
}
else {
$audit_update = "INSERT INTO audit (code,info) VALUES ('17',Monitor $monitor has been added by manual scan by $uid')";
mysqli_query($conn, $audit_update);
$audit_update = "INSERT INTO audit (code,info) VALUES ('15',Monitor $monitor has been updated to deployed by $uid')";
mysqli_query($conn, $audit_update);
}
第1-11行是不起作用的行。
答案 0 :(得分:0)
工作脚本:
$monitor_insert = "INSERT INTO monitors (serial,room,deployed,asset) VALUES ('$monitor','5','$timestamp','$asset')" or die("Error " . mysqli_error($conn));
if (!mysqli_query($conn, $monitor_insert)) {
$monitor_update = "UPDATE monitors SET serial = '$monitor', room = '5', deployed = '$timestamp', asset = '$asset')" or die("Error " . mysqli_error($conn));
if (!mysqli_query($conn, $monitor_update)) {
echo "<p>Nothing Worked!!!</p>";
}
else {
$audit_update = "INSERT INTO audit (code,info) VALUES ('15','Monitor $monitor has been updated to deployed by $uid')";
mysqli_query($conn, $audit_update);
}
}
else {
$audit_update = "INSERT INTO audit (code,info) VALUES ('17','Monitor $monitor has been added by manual scan by $uid')";
mysqli_query($conn, $audit_update);
$audit_update = "INSERT INTO audit (code,info) VALUES ('15','Monitor $monitor has been updated to deployed by $uid')";
mysqli_query($conn, $audit_update);
}