简体   繁体   English

更新php后刷新页面

[英]Refresh Page after update php

i need a javascript to help me refresh my page after i update the data. 我需要一个JavaScript来帮助我更新数据后刷新我的页面。 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'");

 }

?>

只需将此PHP放在更新逻辑的末尾,它必须在任何HTML输出之前;

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. 像Blake说的那样,ajax或PHP可能会更受欢迎。 Otherwise, to answer your question, you can use: document.location = window.location.href 否则,要回答您的问题,您可以使用: document.location = window.location.href

如果您需要javascript,请使用以下代码:

<script>window.top.location='mypage.html'</script>

You cannot refresh your browser page using PHP. 您无法使用PHP刷新浏览器页面。 You have to use either META or Javascript. 您必须使用META或Javascript。

Using Meta tag inside <HEAD> and </HEAD> : <HEAD></HEAD>使用Meta标签:

<meta http-equiv="refresh" content="0; url=http://example.com/">

Using Javascript: 使用Javascript:

location.reload(true)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM