如何创建允许多个操作的提交按钮?在这种情况下,我希望按钮添加新数据并使用一个提交按钮打印新数据。
但是,在我的提交按钮上添加onclick="printContent('div1')"
后,INSERT查询不起作用。因此,它将打印旧的最新信息,因为没有添加新数据。
的index.php:
<html>
<?php
// Turn off all error reporting
error_reporting(0);
include 'dbconnect.php';
?>
<head>
<script>
// script to print partial information only
function printContent(el){
var restorepage = document.body.innerHTML;
var printcontent = document.getElementById(el).innerHTML;
document.body.innerHTML = printcontent;
window.print();
document.body.innerHTML = restorepage;
}
</script>
</head>
<body>
<form method="POST" action="">
<button name="submit" type="submit" id="printStuff" class="btn v-btn no-three-d" onclick="printContent('div1')">PRINT!</button>
</form>
<?php
if(isset($_POST["submit"])){
$sql2 = "INSERT INTO Q_postitem (service_ID, created_time, queue_No)
SELECT 1, CONVERT_TZ(CURRENT_TIMESTAMP,'+00:00','+8:00'), max(queue_No)+1 FROM Q_postitem WHERE service_ID=1";
if (mysqli_query($con, $sql2)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql2 . "" . mysqli_error($con);
}
echo "<br>".$sql2;
mysqli_close($con);
}
?>
<div id="div1" style="display: none;">
//ECHO NEW ADDED DATA HERE TO PRINT
</div>
</body>
</html>