[英]Refreshing to the data posted page after database insertion in php
Suppose I have three pages in php: Page1, Page2 and Page3. 假设我在php中有三个页面:Page1,Page2和Page3。
href="Page2.php?id='$myid'"
, where $myid
has been posted in a variable id
to the Page2.php if I click that link. href="Page2.php?id='$myid'"
,如果我单击该链接,其中$myid
已以变量id
的形式发布到Page2.php。 $newid
where I am storing the id
variable (ie posted from Page1.php) using GET. $newid
使用GET存储id
变量(即从Page1.php发布)。 It is like- $newid=$_GET['id'];
$newid=$_GET['id'];
- $newid=$_GET['id'];
. mySql
) correctly. mySql
)。 Now my question is, after successful insertion of data to the database in Page3.php, how can I revert back to Page2.php since there is a variable id
from Page1.php ( $newid=$_GET['id'];
) using a javascript message box. 现在我的问题是,在成功将数据插入到Page3.php中的数据库后,由于Page1.php中有变量
id
( $newid=$_GET['id'];
),我该如何恢复为Page2.php $newid=$_GET['id'];
使用JavaScript消息框。 Even I have stored that $newid
to a SESSION
variable also in Page2. 甚至我也将
$newid
存储到SESSION
变量中,也存储在Page2中。 Please help. 请帮忙。
Assuming you want to manipulate the PHP variable in JavaScript or run logic against it, I would recommend making use of the HTML DOM itself as an intermediary point. 假设您要在JavaScript中操纵 PHP变量或对其进行逻辑处理,我建议您将HTML DOM本身用作中介点。
First, echo the PHP variable somewhere on the page: 首先,在页面上的某处回显PHP变量:
<span id="php">
<?php echo $newid; ?>
</span>
This output location can be hidden with CSS if need be. 如果需要,可以使用CSS 隐藏此输出位置。
#php {
display: none;
}
Then, target the element with JavaScript: 然后,使用JavaScript定位元素:
var id = document.getElementById('php').innerHTML;
You can then manipulate the variable as you would like, running conditional logic, and redirecting accordingly: 然后,您可以根据需要操纵变量,运行条件逻辑并相应地重定向:
var id = document.getElementById('php').innerHTML; if (id == 2) { // Logic triggers window.location = "page1.php?id=" + id; }
<span id="php">2</span>
The above example will pass the id
parameter as $_GET
to page 1. 上面的示例会将
id
参数作为$_GET
传递给第1页。
However, it's important to note that $_SESSION
data persists between pages, so you could always just use $_SESSION['id']
directly, from any of your pages. 但是,请务必注意,
$_SESSION
数据在页面之间仍然存在,因此您始终可以直接从任何页面直接使用$_SESSION['id']
。
Hope this helps! 希望这可以帮助! :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.