首页 > 解决方案 > 编辑/更新客户端后,如何重定向到新页面以回显客户端 ID?

问题描述

我想知道是否一些更有经验的 PHP 编码人员可以帮助我解决这个问题:

  1. 我有一个 edit.php 页面,它显示要在表单字段中更新的当前客户端数据。
  2. 此时单击的更新按钮只是转到页面clients.php(显示所有客户端数据,包括更新的客户端数据)
  3. 我的目标是当单击更新按钮而不是作为重定向转到 clients.php 并显示一个充满客户的表格时,我希望它仅重定向到 report.php 页面上的单个客户信息并让它回显当前更新了表中的客户数据。

我得到的只是下面的语法错误。

语法错误,意外的 '' (T_ENCAPSED_AND_WHITESPACE),需要 '-' 或标识符 (T_STRING) 或变量 (T_VARIABLE) 或数字 (T_NUM_STRING)

下面是edit.php页面上的重定向代码,然后是我想要重定向到的reports.php页面下方,但只回显当前客户端ID的数据。

if($run_update){

    header("Location: reports.php?cus_id=<?php echo $result['id'] ?>"); 

          keepmsg('<div class="alert alert-success text-center">
              <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
              <strong>Success!</strong> Client updated successfully.
        </div>');

} else {

  keepmsg('<div class="alert alert-danger text-center">
              <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
              <strong>Sorry!</strong> Client could not be updated.
        </div>');
}

下面是简单的reports.php 页面。这是我试图重定向到并仅按 ID 显示当前客户数据

<div class="container">

<div class="jumbotron">

    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <small class="pull-right"><a href="edit.php?cus_id=<?php echo $row['id'] ?>" class='btn btn-danger'>Edit Client</a> </small>
                <h2 class="text-center invert"> Client Info: <span class="font-weight-light"><?php echo $row['deceased'] ?></span></h2>
                <hr>
            </div>
        </div>
    </div>

    <br>

    <div class="table-responsive table-wrapper">
        <table class="table table-bordered table-hover text-center">
            <thead>
                <tr>
                    <th class="text-center">Job Type</th>
                    <th class="text-center">Name of Deceased</th>
                    <th class="text-center">Plot Number</th>
                    <th class="text-center">Cemetery</th>
                </tr>
            </thead>
            <tbody class="invert_td">   
                <tr> 
                    <td><?php echo $row['jobtype'] ?></td>
                    <td><?php echo $row['deceased'] ?></td>
                    <td><?php echo $row['plot'] ?></td>
                    <td><?php echo $row['cemetery'] ?></td>
                </tr>
            </tbody>
        </table>
    </div>

</div>

如果有帮助,请在下方,如果我在 edit.php 页面上的表单中的第一行代码

<form class="form-horizontal" role="form" method="post" action="edit.php?cus_id=<?php echo $client_id ?>">

标签: phpformsredirect

解决方案


嗨 Mohammed 我在我的 functions.php 中有一个函数虽然我不确定这是否是你在标题中传递的意思?

function redirect($page){

header("Location: {$page}{$result} ['id']");   

}

我创建了这个函数,但它仍然没有带我到正确的客户端信息页面,例如 http://localhost:9090/wmdb/admin/reports.php?cus_id=132

只为

http://localhost:9090/wmdb/admin/reports.php?cus_id=


推荐阅读