Reputation: 91
When the form is submitted a query runes and updates the background id after that it reloads itself. Now the problem is that i need to reload the page again to see the updated background. So my question is : How do i apply changes instant after my query is done.
My form :
<form id="myForm" method="get">
<div class="row">
<div class="span4 info1">
<section class="widget">
<img src="../bootstrap/img/thumb/0.jpg" width="auto" height="auto">
<?php
if ($selectedBg == '0') {
echo '<h2>Current one</h2>';
}
?>
<input type="radio" name="options[]" value="0" onclick="document.getElementById('myForm').submit();"/>Choose Background
</section>
</div>
</div>
</form>
my query
<?php
$checked = $_GET['options'];
for($i=0; $i < count($checked); $i++) {
$sql = 'UPDATE blog_users SET background = '.$checked[$i].' WHERE username=?';
$bg = $db->prepare($sql);
$bg->execute(array($session->username));
}
?>
Upvotes: 0
Views: 139
Reputation: 12341
You could redirect to the same page after you're done processing the query,
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
That's what I'd do. Besides, this would prevent unnecessary form resubmissions.
Upvotes: 1