I’m trying to make a plugin to a slider I already made an admin panel, and I can update the db, but I've a problem after I put the new data and press update - its updates the db, but it is not shown on the page. I need to refresh the admin page, and only after that, I can see the changes.
How can I automatically refresh the page?
- I try to call js func etc.:window.location.reload()
- I tried a lot but nothing seemed work
- I have a little understanding of JavaScript and I don't know what the problem is and how to fix it
Code:
<form action="" method="post">
<?php
for($i=1; $i<=5; $i++)
{
$sliderows=getSliderData($i);
echo '<div id="single-slide-wrap">
<div id="slide-num">
<p id="stitle"><strong>#'.$i.'</strong></p>
<input name="slideradio" type="radio" value="'.$i.'" />
</div><!--slide-num-->
<div id="slide-pic">
<img alt="" src="'.$sliderows['img'].'" style="width: 120px; height: 80px;" />
</div><!--slide-pic-->
<div id="slide-text">
<strong>Img Url: </strong>'.$sliderows['img'].'<br />
<strong>Title: </strong>'.$sliderows['title'].'<br />
<strong>Url: </strong>'.$sliderows['url'].'<br />
</div><!--slide-text-->
</div><!--single-slide-wrap-->';
}
?>
<h3>update Slider</h3>
IMAGE URL: <input type="text" name="img" />
TEXT: <input type="text" name="text" />
URL: <input type="text" name="url" />
<input type='submit' name="submit" value='update' />
</form>
<?php
if (isset($_POST['submit'])) {
if (isset($_POST['slideradio'])) {
switch ($_POST['slideradio']) {
case '1':
update_slider_db(1);
break;
case '2':
update_slider_db(2);
break;
case '3':
update_slider_db(3);
break;
case '4':
update_slider_db(4);
break;
case '5':
update_slider_db(5);
break;
}
}
}
echo '</div>';
}
i just found the answer - after a lot of digging:
i insert the code:
header("location: " . $_SERVER['REQUEST_URI']);
into update_slider_db function - after updating the db.
and then add:
}
into function.php