Reputation: 179
<fieldset>
<form method="post" enctype="multipart/form-data">
<table>
<tr><td colspan="2"><div align="center" class="hed"> Personal Details </div></td>
</tr>
<tr>
<td><h3>Name:</h3></td>
<td><input type="text" name="name" value="<?php echo $row['name']; ?>" /></td>
</tr>
<tr>
<td><h3>DOB</h3></td>
<td><input type="text" name="dob" id="datepicker" value="<?php echo $row['dob']; ?>" /></td>
</tr>
<tr>
</tr>
<td colspan="2">
<input type="submit" name="update" value="Update"/></td>
</tr>
</table>
</form>
</fieldset>
<?php
if (isset($_POST['update']))
{
$stmt = $con->prepare("UPDATE tbl SET name = ? , dob = ? WHERE id = ?");
$stmt->bind_param('ssi',
$_POST['name'],
$_POST['dob'],
$_REQUEST['id']);
$stmt->execute();
$stmt->close();
}
?>
This code works fine but after the update i ve to reload the page to see the result. i tried to create the alert box to reload the page that also dint work and i dont want any action page for the redirection.. how can i reload the page without any action page ??
p.s.onsubmit="setTimeout(function () { window.location.reload(); }, 10)"
i tried this also dint work
Upvotes: 0
Views: 103
Reputation: 157980
To refresh the exact page you have been on:
header('Location: '.$_SERVER['REQUEST_URI']);
Upvotes: 0
Reputation: 619
Just add one line below close line If you want same page then
header('Location: '.$_SERVER['PHP_SELF']);
If you want redirect to another page then copy below page
header('Location: pageName.php');
Upvotes: 0
Reputation: 2159
You can update the header in php: header. So that the page will get load.
<?php
$key = $_GET["id"]; //get your id in $key variable
if (isset($_POST['update']))
{
$stmt = $con->prepare("UPDATE tbl SET name = ? , dob = ? WHERE id = ?");
$stmt->bind_param('ssi',
$_POST['name'],
$_POST['dob'],
$_REQUEST['id']);
$stmt->execute();
$stmt->close();
header("Location: yourPageName.php?id=$key"); //call get method here
}
?>
Upvotes: 1