hey guys, I’m not understanding something that’s going on here. I have PHP code in 2 parts of my page. 1 script to echo out traffic data, and a 2nd script embedded inside a js function that is called when a button is clicked. The first time I visit the page, the data echoes out just fine, however if I reload the page by pressing the “reload” button on the browser’s address bar, the 2nd script inside the js function is apparently executing cuz there is nothing echoing out, indicating that the database table is empty. Here is the HTML for my button:
<input type="button" onclick="emptyReport();" id="Button1" name="button" value="Clear Report" style="position:absolute;left:1px;top:1px;width:96px;height:25px;font-family:Arial;font-size:13px;z-index:5">
and this is the js function that is causing the problem:
< script type=“text/javascript” >
function emptyReport() {
if (confirm(‘Are you sure you want to clear the report data?’)) {
<?php
$dbHost = "localhost";
$dbName= "rptDatabase";
$dbUsername = "username";
$dbPassword = "password";
$conn = mysqli_connect($dbHost, $dbUsername, $dbPassword, $dbName);
//throw the old report data into a log history table
mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
$conn = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
//Add current traffic data to a history log table
$stmt = $conn->prepare("INSERT INTO tblTrafficHistory (ip, host, page, date, time)
SELECT ip, host, page, date, time FROM tblTraffic");
$stmt->execute();
//Delete traffic data from display report and start fresh
$stmt = $conn->prepare("DELETE FROM tblTraffic");
$stmt->execute();
$stmt->close();
$conn->close();
?>
//reload the page to show that the report data has been cleared
alert('Report data has been cleared! You will now only see visitor information from this point on.');
header("Refresh:0");
} else {
}
}
< /script >
can someone tell me my error?