php - 如何使用 php 文件更改不同 php 网页上的值

标签 php html mysql

我有一个包含两个表单的网页。然后,我有一个单独的 .php 文件,其中包含提交每个文件时我想要发生的情况的代码。

第一个表单是搜索表单,操作在以下 php 文件上执行。

<?php
include newCustomer.php;
connect('final');//connect to DB

$query = $_POST['searchDB']; 
    $query = htmlspecialchars($query);
    $query = mysql_real_escape_string($query); 

     $data = mysql_query("SELECT * FROM customer WHERE First_Name LIKE '$query'") ;//query the DB with search field in colleumn selected//

     //$data = mysql_query("SELECT * FROM customer INNER JOIN address ON customer.ID = address.Customer_ID LEFT OUTER JOIN sites ON address.ID = sites.address_ID WHERE upper(customer.$field) LIKE'%$query%'") ;

    if($data === FALSE) {
    $error = 'Query error:'.mysql_error();
    echo $error;
    }
    else
    {

    $test = array();
    $colNames = array();
    while($results = mysql_fetch_assoc($data)){// puts data from database into array, loops until no more

    $test[] = $results;

        }
         $anymatches=mysql_num_rows($data); //checks if the querys returned any results
        if ($anymatches != 0) {
    $colNames = array_keys(reset($test));

    }

            if ($anymatches == 0) 
                    { 
                        echo "Sorry, but we can not find an entry to match your query<br><br>"; 
                    } 

    } 
header("location: newCustomer.php");
echo test;
die();
?>

我想在 newCustomer 页面上使用数组中包含的数据。但我无法让它出现,我尝试在 search.php 文件中的随机位置回显“test”,但它不会出现在 newCustomer 页面上。

如何在两者之间传递信息?

最佳答案

php header 函数将用户重定向到新页面,它在客户端(在浏览器中)而不是服务器端执行此操作。

因此,当您执行 header("location: newCustomer.php"); 时,这不会发生在服务器端,只会发生在客户端。这意味着没有信息可以从上面的代码(表单操作页面)传递到 newCustomer.php。

要解决此问题,您需要将数据存储在服务器上的某个位置,然后从 newCustomer.php 中检索它。很难确切地说在您的具体情况下应该做什么,因为我不知道您的代码,但为此您可以使用 sessions , cookies 、数据库等

关于php - 如何使用 php 文件更改不同 php 网页上的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16965205/

相关文章:

mysql - 在 MySQL 中存储包含 2 个固定字符和 4 个数字的数据的性能方式?

php includes 有什么方法可以只包含与该文档相关的文件吗?

php - Fine Uploader 需要分块文件并重新加入

javascript - 如何编写一个 js 来替换标签内的文本?

html - 如何将下拉菜单,菜单向左移动?

php - 获取 mysql 条目的 CHAR_LENGTH 作为 php 变量

php - 无法让贝加尔在子目录中运行

php - 将 JSON 和 HTML 安全地提供给 JavaScript

javascript - 数据以凌乱的方式加载到页面上

MySQL:查询本周数据