简体   繁体   English

在数据库查询后将变量从一个PHP页面发送到另一页面

[英]Sending Variables from one PHP Page to another after DB query

So I want to make a search form that queries data from a MySQL DB and then feeds the results to another PHP page as in eg: 因此,我想制作一个搜索表单,该表单查询MySQL数据库中的数据,然后将结果提供给另一个PHP页面,例如:

url.com/page?var1=dbresult&var2=dbresult2  

I know how to send the request to mysql and receive the data, but how do i forward this data to the other php script automatically? 我知道如何将请求发送到mysql并接收数据,但是如何将这些数据自动转发到其他php脚本? The issue is that I can't change the second PHP page as it is part of a plugin. 问题是我无法更改第二个PHP页面,因为它是插件的一部分。 So basically I'll need to forward the user upon submission of the form and after the SQL query to the second PHP page, providing the data as shown in the example. 因此,基本上,我将需要在提交表单时以及在SQL查询之后将用户转发到第二个PHP页面,并提供示例中所示的数据。

Thanks for any hint! 感谢您的提示!

i'm not sure what exactly your requirement but this is answer i think you want, you want to append the data which fetch from db into your url--> url.com/page?var1=dbresult&var2=dbresult2 我不确定您的要求到底是什么,但这是我想得到的答案,您想将从db获取的数据附加到您的url.com/page?var1=dbresult&var2=dbresult2 > url.com/page?var1=dbresult&var2=dbresult2

so when you fetch data from db, you should add this line in your php code 因此,当您从数据库获取数据时,应在php代码中添加此行

<a href='url.com/page.php?var1=".$dbresult."&var2=".$dbresult2 ." '>click here</a>

where $dbresult and $dbresult2 = data fetch from db 其中$ dbresult和$ dbresult2 =从数据库获取数据

Including action page is the only way recommended by professionals. 包括操作页面是专业人员推荐的唯一方法。

In the action page, you have the server side code that process the forms and interact with the DB. 在操作页面中,您具有服务器端代码,用于处理表单并与DB进行交互。 No HTML content is there in the action page. 操作页面中没有HTML内容。

If the name of a page is **myform.php** , then the action page can be called something like- **myform_action.php** [or any other name] 如果页面名称是**myform.php** ,则可以将操作页面称为- **myform_action.php** [或任何其他名称]

But include myform_action.php in myform.php like: 但包括myform_action.phpmyform.php ,如:

<?php include 'myform_action.php'; ?>

This is not a ultimate solution for this question. 这不是此问题的最终解决方案。 There are many other PHP stuffs works along with this for this requirement. 为此,还有许多其他的PHP东西可以一起工作。

In case of redirection , PHP uses a function header() . 重定向的情况下,PHP使用函数header() The header() function sends a raw HTTP header to a client. header()函数将原始HTTP标头发送到客户端。 Here is the syntax: 语法如下:

void header ( string $string [, bool $replace = true [, int $http_response_code ]] )

An example: 一个例子:

<?php
header("Location: http://www.example.com/"); /* Redirect browser */
?>

OR 要么

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. 请记住,必须先通过常规HTML标记,文件中的空白行或从PHP发送任何实际输出,然后调用header()。 It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. 读取包含,或要求函数或另一个文件访问函数的代码,并在调用header()之前输出空格或空行,这是一个非常常见的错误。 The same problem exists when using a single PHP/HTML file. 使用单个PHP / HTML文件时,存在相同的问题。

<html>
<?php
/* This will give an error. Note the output
 * above, which is before the header() call */
header('Location: http://www.example.com/');
exit;
?>

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

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