I have a form with a submit button. When i click this button i dont want to be redirected to the page connection.php, that is listed in action="". But insteed i want it to just show pop-up window that says successful or not successful, and let the connection2.php do its thing in the background.
HTML:
<form action="connection2.php" method="post">
<input type="date" name="date" placeholder="Name" required="">
<input type="submit" name="submit" id="submit" class="strelka-send" value="Insert">
<div class="clear"> </div>
</form>
CONNECTION2.PHP:
<?php
# Connection
$servername = "";
$connectionInfo = array(
"Database"=>"",
"UID"=>"",
"PWD"=>""
);
$conn = sqlsrv_connect($servername, $connectionInfo);
if( $conn === false ) {
echo "Error (sqlsrv_connect): ".print_r(sqlsrv_errors(), true);
exit;
}
# Parameters
$Date = $_POST['date'];
$params = array
(&$Date);
# Statement
$sql = "INSERT INTO table([Date]) VALUES
(?)";
$stmt = sqlsrv_prepare($conn, $sql, $params);
if ($stmt === false) {
echo "Error (sqlsrv_prepare): ".print_r(sqlsrv_errors(), true);
exit;
}
if (sqlsrv_execute($stmt)) {
echo "Statement executed.\n";
} else {
echo "Error (sqlsrv_execute): ".print_r(sqlsrv_errors(), true);
}
# End
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
?>
<!DOCTYPE html>
<html>
<body>
<br>
<h1>SUCCESS</h1>
<script>
setInterval(function(){
window.location.href="link_to_index.html" }, 5000);
</script>
</body>
</html>
So far i have set timer on the page connection2.php that opens after form is submited, and then goes back to previous page. But it is not the nicest solution.