i need a javascript to help me refresh my page after i update the data. i have coded out t he update function all i need to refresh the page after the data is updated how do i do that.
This is what i have done so far
<?php
mysql_connect("localhost","fbappsadmin","dbP@ssw0rd") or die(mysql_error()) ;
mysql_select_db("jetstardatabase") or die(mysql_error()) ;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$options = array(
'1' => 1,
'2' => 2,
);
if (isset($_POST['list'])) {
$value = (int)$_POST['list'];
} else {
$value = 0; // default value;
}
$cmeter = $cmeter - $value;
mysql_query("INSERT orders SET quantity='$value',fbId='$fbme',fbName='$fbName', email ='$fbEmail', dealName='$dealName'" );
mysql_query("UPDATE stardeal SET cmeter='$cmeter'WHERE dealId='$dealId'");
}
?>
i need a javascript to help me refresh my page after i update the data. i have coded out t he update function all i need to refresh the page after the data is updated how do i do that.
This is what i have done so far
<?php
mysql_connect("localhost","fbappsadmin","dbP@ssw0rd") or die(mysql_error()) ;
mysql_select_db("jetstardatabase") or die(mysql_error()) ;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$options = array(
'1' => 1,
'2' => 2,
);
if (isset($_POST['list'])) {
$value = (int)$_POST['list'];
} else {
$value = 0; // default value;
}
$cmeter = $cmeter - $value;
mysql_query("INSERT orders SET quantity='$value',fbId='$fbme',fbName='$fbName', email ='$fbEmail', dealName='$dealName'" );
mysql_query("UPDATE stardeal SET cmeter='$cmeter'WHERE dealId='$dealId'");
}
?>
Share
Improve this question
asked Jan 12, 2012 at 16:01
Nicholas LimNicholas Lim
95 silver badges8 bronze badges
3
- Can you give us more details of the context ? – jbrtrnd Commented Jan 12, 2012 at 16:03
- Seriously hope this code isn't actually for JetStar! – Treffynnon Commented Jan 12, 2012 at 16:05
- @Treffynnon I hope so too, looks like he's even put the login details in! – Dunhamzzz Commented Jan 12, 2012 at 16:35
5 Answers
Reset to default 1Just put this PHP at the end of your update logic, it must be before any HTML output;
header("Location: /mypage.html");
Web pages work like this:
page (client) -> request (made in url) (server) -> new page (client)
By sending a request to the server, the server generates the new page and serves it back to the browser. You have the middle part, you need the entry and exit pages.
Like blake said, ajax or PHP would probably be prefered. Otherwise, to answer your question, you can use:
document.location = window.location.href
If you need javascript, then use this code:
<script>window.top.location='mypage.html'</script>
You cannot refresh your browser page using PHP. You have to use either META or Javascript.
Using Meta tag inside <HEAD>
and </HEAD>
:
<meta http-equiv="refresh" content="0; url=http://example./">
Using Javascript:
location.reload(true)