Reputation: 57
now i face a problem with user will see the popout with "update sucessfully" if he reload the page or backward to the page.Anyone having idea of how to remove ?id=2 after click ok on pop out?
Here is my code:
update_action.php
$updresult = mysqli_query($conn, $sqlu);
if (!$updresult)
echo "Unable to update record". mysqli_error($conn);
else
{
header('Location: index.php?id=2' );
mysqli_close($conn);
}
?>
index.php
if ($id == 1)
{
?>
<script>
alert("Invalid user name or password, Try again");
</script>
<?php
}
else if($error_id == 2)
{
?>
<script>
alert("Update Sucessfully!");
</script>
<?php
}
Upvotes: 0
Views: 1722
Reputation: 42
What you need is to change the url with javascript without reloading the page.
Check out: https://wiki.selfhtml.org/wiki/JavaScript/History/pushState
You can put this after your alert/confirm
// Remove the "?.." from the url
var url = [location.protocol, '//', location.host, location.pathname].join('');
// maybe check if the browser supports history.pushState
history.pushState({}, '', url);
Upvotes: 0
Reputation: 722
if ($id == 1)
{
?>
<script>
alert("Invalid user name or password, Try again");
</script>
<?php
}
else if($error_id == 2)
{
?>
<script>
alert("Update Sucessfully!");
//---------- added ---------------
window.location.href= 'index.php';
//-------------------------
</script>
<?php
}
Upvotes: 1